Skip to content

fix(preview): Only exchange messages with the preview frame - #4430

Merged
tvdeyen merged 1 commit into
mainfrom
fix-preview-messaging
Oct 30, 2026
Merged

tvdeyen merged 1 commit into
mainfrom
fix-preview-messaging

Conversation

@tvdeyen

@tvdeyen tvdeyen commented Oct 30, 2026

Copy link
Copy Markdown
Member

What is this pull request for?

The admin posted messages to the preview frame with "*" as target origin and accepted Alchemy.focusElementEditor and Alchemy.previewReady messages from any window. Any page loaded into the preview frame received the admin's messages, and any other frame or opener could focus element editors.

The admin now only handles messages whose source is the preview frame, and posts to the origin the preview reported in its Alchemy.previewReady message instead of "*". Taking the origin from that message instead of the iframe's src keeps this working when the frontend lives on another origin (e.g. a headless frontend configured as preview.host) or redirects (apex to www, http to https). Nothing is sent before the preview reported ready, since there is nobody listening yet.

The preview script itself already posts to and accepts messages from its own origin, so the Rails preview is unaffected.

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

The admin posted to the preview with "*" and accepted messages from any window, so any frame or opener could focus element editors and every page loaded into the preview received the messages. Taking the target origin from the preview's ready message keeps this working when the frontend lives on another origin or redirects, without trusting other senders.
@tvdeyen tvdeyen added bug backport-to-8.4-stable Needs to be backported to 8.4-stable labels Oct 30, 2026
@tvdeyen
tvdeyen requested a review from a team as a code owner October 30, 2026 07:06
@netlify

netlify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for alchemy-guides canceled.

Name Link
🔨 Latest commit 2021581
🔍 Latest deploy log https://app.netlify.com/projects/alchemy-guides/deploys/6ae442037eb05b860578342b

@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.41%. Comparing base (38e923a) to head (2021581).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4430   +/-   ##
=======================================
  Coverage   98.41%   98.41%           
=======================================
  Files         371      371           
  Lines        9845     9845           
=======================================
  Hits         9689     9689           
  Misses        156      156           
Flag Coverage Δ
mariadb 97.04% <ø> (ø)
mysql 95.96% <ø> (ø)
postgresql 95.96% <ø> (ø)
sqlite 95.96% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tvdeyen
tvdeyen merged commit 3d78aee into main Oct 30, 2026
40 checks passed
@tvdeyen
tvdeyen deleted the fix-preview-messaging branch October 30, 2026 07:32
@alchemycms-bot

Copy link
Copy Markdown

💔 All backports failed

Status Branch Result
❌ 8.4-stable Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

backport --pr 4430

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

@alchemycms-ci-bot

Copy link
Copy Markdown
Collaborator

💚 All backports created successfully

Status Branch Result
✅ 8.4-stable

Questions ?

Please refer to the Backport tool documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-8.4-stable Needs to be backported to 8.4-stable bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants