Skip to content

Round-trip wizard log-entry images through Trix#40

Merged
pablojimeno merged 1 commit into
mainfrom
pablojimeno/wizard-log-entry-images
May 8, 2026
Merged

Round-trip wizard log-entry images through Trix#40
pablojimeno merged 1 commit into
mainfrom
pablojimeno/wizard-log-entry-images

Conversation

@pablojimeno
Copy link
Copy Markdown
Member

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 via editor.loadHTML, but Trix's HTML parser does not understand that element. @rails/actiontext only registers an upload handler — it does not extend the parser. So Trix dropped the attachments before form submit and process_summary ended up text-only.

Fix: emit <figure data-trix-attachment="{json}">, 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 picker now exposes blob filesize / width / height / previewable so 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> inside figure.attachment on the public page.
  • bundle exec rubocop clean.
  • Manual verification by user: images now appear on the published page after picking log entries with media.

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.
@pablojimeno pablojimeno merged commit cb857b4 into main May 8, 2026
5 checks passed
@pablojimeno pablojimeno deleted the pablojimeno/wizard-log-entry-images branch May 8, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant