Skip to content

fix(live-preview): foreign postMessage events reset client-side state #12925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

jacobsfletch
Copy link
Member

@jacobsfletch jacobsfletch commented Jun 24, 2025

Needed for #12860.

If the admin panel broadcasts foreign postMessage events, i.e. those without the payload-live-preview signature, client-side live preview subscriptions will reset back to initial state.

This is because we dispatch two postMessage events in the admin panel, one for client-side live preview to catch (payload-live-preview), and the other for server-side live preview (payload-document-event). This was not previously noticeable because both events would only get called simultaneously on initial render, where initial state is already the expected result.

Now that Live Preview can be freely toggled on and off, both events are frequently dispatched and very obviously disregard the current working state.


@jacobsfletch jacobsfletch merged commit 67fa5a0 into main Jun 26, 2025
92 checks passed
@jacobsfletch jacobsfletch deleted the fix/live-preview-message-handler branch June 26, 2025 18:05
Copy link
Contributor

🚀 This is included in version v3.44.0

@PeteJStewart
Copy link

I had experience this issue with the Svelte live preview package I wrote, but had assumed it was a glitch in the way I wrote it.
I created a fix in the package, but wasn't totally happy with it, so I'm pleased to see this was actually a bug in live preview that has now been resolved! 🥳

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

Successfully merging this pull request may close these issues.

None yet

2 participants