Skip to content

Fix PHP snippet run controls#3636

Merged
adamziel merged 1 commit into
trunkfrom
adamziel/kolkata
May 14, 2026
Merged

Fix PHP snippet run controls#3636
adamziel merged 1 commit into
trunkfrom
adamziel/kolkata

Conversation

@adamziel
Copy link
Copy Markdown
Collaborator

What changed

  • Make <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.
  • Add Ctrl+Enter and Cmd+Enter shortcuts for running the focused snippet.
  • Add a branded footer link: "PHP Code Snippet powered by WordPress Playground".
  • Add Playwright coverage for the branding link, first-click Run behavior, and keyboard shortcut behavior.

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:uncommitted
  • PATH=/usr/local/opt/node@22/bin:$PATH npx nx lint playground-website
  • PATH=/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.js fail to load. The new first-click and shortcut tests pass independently.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 shadowRoot listener 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'
@adamziel adamziel merged commit 7e68c5f into trunk May 14, 2026
55 checks passed
@adamziel adamziel deleted the adamziel/kolkata branch May 14, 2026 13:53
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.

2 participants