Round-trip wizard log-entry images through Trix#40
Merged
Conversation
The publication wizard injected log-entry media into the Trix editor as
`<action-text-attachment sgid="…">` markup, but Trix's HTML parser does
not understand that element. `@rails/actiontext` only registers an
upload handler — it does not extend the parser. So when the editor
serialised on submit, the attachments were silently stripped and the
saved `process_summary` ended up text-only. On the published page,
participants saw the log-entry body and caption but no images.
Fix: emit `<figure data-trix-attachment="{json}">` markup, which Trix
recognises natively and ActionText round-trips through storage. This is
the same shape `ActionText::Content#to_trix_html` produces when
re-opening saved content. The log-entry picker now exposes blob
`filesize`, `width`, `height`, and `previewable` so the JSON has every
field Trix expects.
A controller test on the published page asserts the storage/render
contract: a body containing the new figure markup renders an actual
`<img>` inside `figure.attachment` on the public page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #39. When participants pick log-entry messages (each with image attachments) in the publication wizard, the images were silently dropped before save — text body and caption survived, attachments did not. Confirmed visually by user.
Root cause: the wizard JS was injecting
<action-text-attachment sgid="…">markup viaeditor.loadHTML, but Trix's HTML parser does not understand that element.@rails/actiontextonly registers an upload handler — it does not extend the parser. So Trix dropped the attachments before form submit andprocess_summaryended up text-only.Fix: emit
<figure data-trix-attachment="{json}">, which Trix recognises natively and ActionText round-trips through storage. This is the same shapeActionText::Content#to_trix_htmlproduces when re-opening saved content. The picker now exposes blobfilesize/width/height/previewableso the JSON has every field Trix expects.Test plan
bin/rails test(735 runs, 0 failures) — added a server-side test asserting the storage/render contract: a body containing the new figure markup renders an actual<img>insidefigure.attachmenton the public page.bundle exec rubocopclean.