Handle browser refresh in Playground iframe#3649
Draft
akirk wants to merge 1 commit into
Draft
Conversation
14d362e to
d9fa125
Compare
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.
Motivation for the change, related issues
Pressing Cmd+R or Ctrl+R while using Playground currently reloads the entire shell. That is especially disruptive for temporary Playgrounds and Personal WP, where the expected browser behavior is to refresh the current WordPress page without tearing down the embedding app.
Implementation details
PlaygroundClient.getCurrentURL()andgoTo()so only the inner WordPress iframe refreshes.remote.htmldocument itself.The mu-plugin piece is needed because the focused document owns the keyboard event. In the normal usage path the frame tree is:
Playground shell -> remote.html -> WordPress iframeWhen focus is inside wp-admin, the site editor, the login screen, or the front end, the browser dispatches Cmd+R or Ctrl+R to the WordPress document. That keydown event does not bubble out to
remote.htmlor to the outer Playground shell, so listeners attached only in those wrappers would miss the shortcut exactly where users most often press refresh. Document-Isolation-Policy can also make it unreliable for the wrapper to reach into the WordPress frame and attach a listener from the outside.The mu-plugin is the existing bridge for WordPress-page scripts. It listens inside the WordPress document, prevents the browser-level page reload, and relays a
playground-refreshmessage back to the shell. Without it, iframe-only refresh would work when focus is in Playground chrome, but not when focus is inside WordPress.Existing Personal WP sites receive this on the next runtime boot without mutating the persisted site files. The web-specific Playground mu-plugin is written to
/internal/shared/mu-plugins/1-playground-web.phpduring boot, before the persisted/wordpressOPFS mount is applied./internal/sharedis runtime-owned storage, so updating this source file updates the bridge script for both new and existing Personal WP sites once they load the new Playground runtime.Testing Instructions (or ideally a Blueprint)
NX_ISOLATE_PLUGINS=false NX_DAEMON=false NPM_CONFIG_CACHE=/tmp/npm-cache NX_CACHE_DIRECTORY=/tmp/nx-cache npm exec nx run playground-website:typecheckNX_ISOLATE_PLUGINS=false NX_DAEMON=false NPM_CONFIG_CACHE=/tmp/npm-cache NX_CACHE_DIRECTORY=/tmp/nx-cache npm exec nx run playground-personal-wp:typecheckNX_ISOLATE_PLUGINS=false NX_DAEMON=false NPM_CONFIG_CACHE=/tmp/npm-cache NX_CACHE_DIRECTORY=/tmp/nx-cache npm exec nx run playground-remote:typecheckESLINT_USE_FLAT_CONFIG=false ./node_modules/.bin/eslint packages/playground/website/src/lib/hooks/use-browser-refresh-shortcut.ts packages/playground/website/src/components/playground-viewport/index.tsx packages/playground/personal-wp/src/lib/hooks/use-browser-refresh-shortcut.ts packages/playground/personal-wp/src/components/playground-viewport/index.tsx packages/playground/remote/src/lib/boot-playground-remote.tsphp -l packages/playground/remote/src/lib/playground-mu-plugin/0-playground.phpphp -l packages/playground/remote/src/lib/playground-mu-plugin/0-playground-php52.phpManual smoke test: