[DX-1518] feat: dark mode for /examples (Sandpack previews)#3473
[DX-1518] feat: dark mode for /examples (Sandpack previews)#3473jamiehenson wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
e096d46 to
ad315ba
Compare
Convert every example variant (React + JavaScript, static markup and the dynamically-rendered .ts/.tsx markup) to render correctly in dark: hardcoded light Tailwind utilities gain `dark:` counterparts and custom CSS gets `.dark`-scoped overrides via the shadcn vars the examples already ship. Semantic and per-user colours (status dots, avatars, cursors, badge hues) are preserved. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Make the runnable /examples previews (Vite subprojects surfaced via Sandpack) track the docs light/dark theme: - Inject a hidden module into each example that bakes in the current theme (adds `.dark`, sets Tailwind darkMode:'class'); the files are regenerated per theme, so a theme change reloads the preview to match — no fragile cross-iframe messaging. - Key the SandpackProvider on the resolved theme so a change fully reloads the preview on a fresh iframe, rather than a hot reload that stacks extra example instances. - Paint the preview on the dark canvas from the first frame (head-injected background + color-scheme) and give the Sandpack preview container a dark background, so there's no white flash on load or language switch. - Dark variants for the example-page README tables. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ad315ba to
eeb928b
Compare
AndyTWF
left a comment
There was a problem hiding this comment.
The colours seem fine, but looks like a few examples have lost their overall structure
| <button | ||
| id="prompt-button" | ||
| class="px-3 py-2 text-sm border rounded-md transition-colors bg-white hover:bg-blue-50 border-gray-300 hover:border-blue-300 cursor-pointer" | ||
| class="px-3 py-2 text-sm border rounded-md transition-colors bg-white dark:bg-gray-900 hover:bg-blue-50 dark:hover:bg-blue-950 border-gray-300 dark:border-gray-700 hover:border-blue-300 dark:hover:border-blue-700 cursor-pointer" |
There was a problem hiding this comment.
This example looks... wrong on the demo site compared to prod. I can't see any buttons and it appears to have lost its structure?
There was a problem hiding this comment.
Believable, I haven't scrutinised this. Will tell the bot to do better.
Dark mode for
/examples(Sandpack previews)Extends the site-wide dark mode (#3466, now merged) to the
/examplespages. The runnable examples are small Vite subprojects surfaced through Sandpack; until now they were light-only regardless of the docs theme. This makes each preview follow the docs theme and gives every example underlying dark-mode styling.How it works
Preview theming — bake the theme in, reload on change (
src/components/Examples/sandpackThemeSync.ts+ExamplesRenderer)The examples run in a cross-origin Sandpack iframe, so the docs page can't restyle them directly. Rather than live cross-iframe messaging (an earlier attempt that proved timing-sensitive and flaky), the theme is baked into each example's files:
.darkand sets TailwinddarkMode:'class', and the<head>paints the dark canvas from the first frame (background+color-scheme) so there's no white flash before the bundle runs.SandpackProvideris keyed on the resolved theme, so a theme change fully reloads the preview on a fresh iframe. A full reload (not an in-place hot reload) tears down the example's side effects — e.g. its Ably connection — rather than stacking a second instance on each toggle. Trade-off: a short reload when the theme changes.--primarytoken is identical in light and dark, souk-text-primary(body text) would stay low-contrast on dark — remapped to--foregroundin dark via a single injected rule.Example styling — all 49 variants (React + JavaScript)
dark:counterparts (default grays); custom CSS gets.dark-scoped overrides via the shadcn CSS-variable blocks the examples already ship..tsx/.html/.css) and the dynamically-rendered markup in.tsfiles (e.g. the annotations components, presence/spaces scripts).pub-sub-live-voting(its own token set, not shadcn) got a dedicated.darktoken block.Docs-side — the example-page README renderer table chrome (
examples.tsx) gaineddark:variants.Verification (review app)
The Sandpack preview only renders behind a logged-in API key, so it can't be verified locally — it needs a deployed, signed-in build (the
review-applabel is applied). Confirmed live on the review app:The latest first-frame-dark and full-reload fixes are deployed for a final pass.
yarn lintclean; 196 unit tests pass.Notes / follow-ups
<head>can't reach); JS previews paint dark from the first frame.dark:bg-gray-900on adark:bg-gray-900parent and can blend; easy to bump togray-800where noticed.darkModeconfig inindex.html— minor infra visible in the example code readers copy.text-grey-500(British spelling — not a real Tailwind class, no-op) left as-is in a couple of chat examples.Testing
Add/keep the
review-applabel for a deployment, then sign in, open a few example pages across product families, and toggle System / Dark / Light in the footer.🤖 Generated with Claude Code