docs: stop hiding snippet fallback prematurely (:defined race)#260
Merged
docs: stop hiding snippet fallback prematurely (:defined race)#260
:defined race)#260Conversation
Reports of "no snippets visible" on the live site, despite the page
shipping 9 <php-snippet> elements + 9 <pre class=\"snippet-fallback\">
blocks: the fallback was hidden by a CSS rule:
php-snippet:defined .snippet-fallback { display: none; }
`:defined` matches the moment `customElements.define('php-snippet', ...)`
runs — i.e. immediately when Playground's php-code-snippet.js is parsed —
*before* the snippet's shadow DOM has any content. So in the gap between
"custom element registered" and "shadow DOM rendered with code + Run
button", the fallback was already gone and the widget hadn't drawn yet.
On a slow client (or one where a later step in the Playground module
fails) the user sees a permanent blank gap.
Fix: drop the `:defined` rule from style.css and hide the fallback
explicitly from page.js's patchSnippet, which only runs once
`shadowRoot.querySelector('pre code')` has actually returned a node.
By that point the snippet's UI is on screen, so swapping the fallback
out is safe. If the cross-origin module never loads, patchSnippet is
never reached and the fallback stays visible.
Verified by rendering the local site twice with chromium:
* Playground module mapped to 127.0.0.1:1 (unreachable) → fallback
<pre> visible for every snippet, code readable.
* Module reachable → custom element renders the editable code area
+ Run button, fallback hidden.
Asset version bumped (20260503-script-unescape → 20260503-fallback-
explicit-hide) so caches refresh.
87/87 snippets still match captured stdout.
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.
Summary
Reports of "no snippets visible" on https://wordpress.github.io/php-toolkit/reference/html.html despite the page shipping 9 `` elements + 9 `<pre class="snippet-fallback">` static fallbacks.
Root cause: the CSS rule
matches the moment `customElements.define('php-snippet', ...)` runs in Playground's module — before the snippet's shadow DOM has any content. In the gap between "custom element registered" and "shadow DOM populated with code + Run button," the fallback was already hidden and the widget hadn't drawn yet. On a slow client (or one where a later step in the Playground module fails) the user sees a permanent blank gap.
Fix: drop the `:defined` rule from `style.css` and hide the fallback explicitly from `page.js`'s `patchSnippet`, which only runs after `shadowRoot.querySelector('pre code')` returns a real node. By that point the snippet's UI is rendered on screen, so swapping the fallback out is safe. If the cross-origin Playground module never loads at all (CSP, adblock, slow network, no-JS), `patchSnippet` is never reached and the fallback stays visible — readers always see the code.
Verification (headless chromium screenshots)
87/87 snippets still match captured stdout. Asset version bumped (`20260503-script-unescape` → `20260503-fallback-explicit-hide`) so browser caches refresh.
Test plan
🤖 Generated with Claude Code