Fix PHP snippet run controls#3636
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Stabilizes <php-snippet> Run behavior during async rendering, adds keyboard shortcuts, and introduces a “powered by” footer link with Playwright coverage.
Changes:
- Delegate Run click handling from a stable
shadowRootlistener and queue early run requests until code is ready. - Add Ctrl/Cmd+Enter keyboard shortcuts plus button accessibility metadata.
- Add a branded “powered by WordPress Playground” footer and Playwright assertions for it and run behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| packages/playground/website/public/php-code-snippet.js | Stabilizes run handling, adds shortcuts, and renders a branded footer link. |
| packages/playground/website/playwright/e2e/php-code-snippet.spec.ts | Adds Playwright coverage for branding link, first-click Run behavior, and keyboard shortcuts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const DEFAULT_ORIGIN = 'https://playground.wordpress.net'; | ||
| const DEFAULT_PHP = '8.4'; | ||
| const DEFAULT_WP = 'latest'; | ||
| const DEMO_URL = 'https://playground.wordpress.net/php-code-snippet-demo.html'; |
| <pre class="output-body"></pre> | ||
| </div> | ||
| <div class="powered-by"> | ||
| <a href="${DEMO_URL}" target="_blank" rel="noopener noreferrer">PHP Code Snippet powered by WordPress Playground</a> |
| } | ||
| .powered-by a:hover { | ||
| text-decoration: underline; | ||
| } |
| } | ||
|
|
||
| function isRunShortcut(event) { | ||
| return event.key === 'Enter' && (event.metaKey || event.ctrlKey); |
| ); | ||
| await expect(snippet.locator('.powered-by a')).toHaveAttribute( | ||
| 'href', | ||
| 'https://playground.wordpress.net/php-code-snippet-demo.html' |
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.
What changed
<php-snippet>Run handling stable across async rendering by delegating click handling from the shadow root and queueing early run requests until the snippet is ready.Why
The first click on Run could feel unreliable because the component's render lifecycle replaced the button and attached the click listener after async snippet loading. Moving the handler to a stable shadow-root listener and waiting for readiness makes the first actionable click run the snippet consistently.
Testing
PATH=/usr/local/opt/node@22/bin:$PATH corepack npm run format:uncommittedPATH=/usr/local/opt/node@22/bin:$PATH npx nx lint playground-websitePATH=/usr/local/opt/node@22/bin:$PATH npx playwright test --config=packages/playground/website/playwright/playwright.config.ts e2e/php-code-snippet.spec.ts --project=chromium -g "Run button invokes|Ctrl\\+Enter"The full focused Chromium snippet spec currently has two failures caused by Vite failing to resolve
isomorphic-git/src/...deep imports from storage code, which makes/client/index.jsfail to load. The new first-click and shortcut tests pass independently.