Skip to content

Docs: fix and restore live code snippet updates in interactive playgrounds#42593

Open
julien-deramond wants to merge 1 commit into
v6-devfrom
v6-dev-jd-docs-fix-playground-dynamic-updates
Open

Docs: fix and restore live code snippet updates in interactive playgrounds#42593
julien-deramond wants to merge 1 commit into
v6-devfrom
v6-dev-jd-docs-fix-playground-dynamic-updates

Conversation

@julien-deramond

@julien-deramond julien-deramond commented Jun 28, 2026

Copy link
Copy Markdown
Member

Description

When interacting with the interactive playgrounds, the live code snippet was never updated to reflect the current state of the controls.

The ButtonPlayground, MenuPlacementPlayground, and NavbarPlacementPlayground components are supposed to update the live code snippet whenever the user changes a control, but nothing was ever updated. codeSnippet was always null because the selector .highlight code didn't match the actual rendered element .astro-code code.

This fixes the selector by targeting <pre class="astro-code"> directly, and replaces the textContent approach with a call to highlightCode from @libs/highlight.

Indeed, without calling this method, the content would have been updated, but without syntax highlighting!

Since Shiki is isomorphic, Vite bundles it for the browser transparently. The returned markup is parsed with DOMParser and the whole <pre> is swapped in the DOM, preserving both the updated content and Shiki's token spans with their theme CSS variables. The codeSnippetPre reference is updated on each swap so subsequent interactions keep targeting the right node.

Live previews

Now, the playground code snippets are updated 🥳

@julien-deramond julien-deramond force-pushed the v6-dev-jd-docs-fix-playground-dynamic-updates branch from 8b63b9f to 370850c Compare June 28, 2026 09:48
@julien-deramond julien-deramond marked this pull request as ready for review June 28, 2026 09:50
@julien-deramond julien-deramond requested a review from a team as a code owner June 28, 2026 09:50
@julien-deramond julien-deramond requested a review from mdo June 28, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Inbox

Development

Successfully merging this pull request may close these issues.

1 participant