You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
attachment-picker Stimulus controller does not sync hidden fields after inline upload #1425
The problem
When using Spina::Parts::Attachment in the admin page editor, uploading a new file via the inline upload button results in signed_blob_id and filename being saved as empty strings, even though the Spina::Attachment record is created correctly and the file is attached.
This causes Spina::Parts::Attachment#present? to return false (since it checks signed_blob_id.present?), and ContentPresenter#attachment_url to return nil, making the uploaded file inaccessible in frontend views.
Root Cause
There are two issues in the interaction between the attachment-picker Stimulus controller and the inline upload Turbo Stream response:
1. pick() is never called after inline upload
The attachment-picker controller's pick() method is bound to the change event on the <select> element. When the inline upload Turbo Stream response appends a new <option selected> to the <select>, the browser does not fire a change event (programmatic DOM mutations don't trigger input events). Therefore pick() is never invoked, and the hidden fields signed_blob_id and filename remain at their previous values (empty strings for a new part).
2. Attribute format mismatch between dropdown options and inline upload options
Even if pick() were called, there is an attribute format mismatch:
Dropdown options (rendered by the Rails select helper in _form.html.erb) use data-* attributes:
The pick() method reads from option.dataset.signedBlobId and option.dataset.filename, which correspond to data-signed-blob-id and data-filename attributes respectively. These are undefined on inline upload options, so even a manual re-selection after upload would write empty strings.
Steps to Reproduce
Create a page with a part that uses Spina::Parts::Attachment
Edit the page in Spina admin
In the Attachment field, click "Upload" and select a file
Save the page
Inspect the page's JSON content — signed_blob_id will be "" and filename will be ""
Workaround: After the inline upload completes, manually re-select the same file from the dropdown. This triggers the change event, pick() reads the data-* attributes from the dropdown option (which has them correctly), and the hidden fields are populated.
Activity