Skip to content

Replace preview/ HTML with React-only docs (foundations + live charts)#2

Merged
aksOps merged 3 commits intomainfrom
feat/react-only-docs
Apr 28, 2026
Merged

Replace preview/ HTML with React-only docs (foundations + live charts)#2
aksOps merged 3 commits intomainfrom
feat/react-only-docs

Conversation

@aksOps
Copy link
Copy Markdown
Contributor

@aksOps aksOps commented Apr 28, 2026

Summary

Removes the last hand-written HTML surface from this repo. Every component, design token, and chart in the docs site is now driven by React + the IIFE bundle pipeline — no more dual maintenance between preview/*.html and the live /docs/<Component>/ pages.

Three commits, each independently reviewable:

  1. refactor(docs): remove hand-written preview/ HTML surface — drops 39 files under preview/ (38 spec cards + _card.css + responsive-check.html), the renderBrandIndex() generator, the "Spec cards" nav entry / footer link / root-index section, the dead .preview-frame CSS, the preview/** copy step in build-site.mjs, and the preview/** path filters in pages.yml / e2e.yml.

  2. feat(docs): auto-generate /docs/foundations/ from design tokens — replaces the deleted brand/colors/type/spacing spec cards with a single live page at /docs/foundations/. Sections: Color (semantic + brand + accent + surface), Typography, Spacing, Radii, Shadows, Motion, plus a TypeScript-types reference. Swatches render via style="background:var(--token)" and a tiny inline script reads computed CSS values + watches data-theme on documentElement so hex labels stay accurate across light/dark/system. No hex hardcoded — colors_and_type.css and src/tokens.ts remain the only source of truth.

  3. feat(docs): live-render chart pages via separate rcs-charts bundle — chart pages were the last surface still showing a static placeholder. New scripts/bundle-entry-charts.ts re-exports src/charts/* plus React + createRoot; build-site.mjs rolls it into rcs-charts.iife.js (~794 KB) as window.RCSCharts. Heavy WebGL peer deps (@deck.gl/core, @deck.gl/layers, d3-force) are externalized — chart components already have canvas2d / SVG fallback paths, which keeps the bundle from ballooning to ~2.3 MB. Runner gains a runChartExample helper; chart pages get <script src="../bundle/rcs-charts.iife.js"> + the chart CSS injected into <head>/<body> only when needed.

Notes on the chart bundle

  • Chart demos render in their own createRoot() and never nest inside the main bundle's React tree, so the "two React instances in one tree" footgun does not apply. They consume theme via CSS custom properties (readChartTheme()), not Context.
  • esbuild emits a separate rcs-charts.iife.css (~1.6 KB) for the dynamic await import("uplot/dist/uPlot.min.css") in Chart.tsx. Linked from chart pages only.
  • Core pages (/docs/Button/, etc.) load only the main bundle — verified via grep on the generated HTML.

Test plan

  • pnpm typecheck clean
  • Sparkline unit tests pass (chart logic touched indirectly)
  • pnpm run build:site succeeds; emits both bundles + foundations page + 58 component pages (51 core + 7 charts)
  • _site/docs/Chart/index.html pulls both rcs.iife.js and rcs-charts.iife.js, includes the chart CSS, calls runChartExample
  • _site/docs/Button/index.html pulls only rcs.iife.js, calls runExample (no chart bundle leakage)
  • _site/docs/foundations/index.html exists, ~36 KB, 36 token-driven swatches via var(--…)
  • Pages workflow green on push (CI)
  • E2E workflow green on push (CI)
  • Manual: open built _site/ via pnpm run serve:site, confirm a chart page renders live, foundations swatches reflect theme switch

Files removed

preview/_card.css, preview/responsive-check.html, and 37 preview/*.html files (brand-, colors-, components-, type-, spacing-*).

Files added

  • scripts/bundle-entry-charts.ts — chart-only IIFE entry
  • _site/docs/foundations/index.html — generated, not committed (built by CI/Pages)

Files modified

  • scripts/build-docs.mjs — drop preview generator, add renderFoundationsPage(), dual-runner support, conditional chart-bundle script tags
  • scripts/build-site.mjs — second esbuild pass for chart bundle, drop preview/ copy step
  • scripts/build-llms.mjs — already taught about charts subpath in a prior PR
  • scripts/parse-source.mjsparseChartsExports() helper (committed earlier)
  • .github/workflows/pages.yml, .github/workflows/e2e.yml — drop preview/** path filters
  • tests/unit/Sparkline.test.tsx — docstring no longer references preview cards

🤖 Generated with Claude Code

aksOps and others added 3 commits April 28, 2026 13:17
The /docs/<Name>/ pages already render every component live via the
IIFE bundle + Babel-standalone runner. The 39 hand-written HTML
"spec cards" under preview/ duplicated that for non-chart components
and were a separate maintenance surface that drifted from the React
truth. Killing them.

Removed:
- 38 preview/components-*.html, brand-*, colors-*, type-*, spacing-*
  files plus responsive-check.html and the shared _card.css.
- renderBrandIndex() in build-docs.mjs and its writeFileSync block.
- "Spec cards" entry from NAV_ITEMS, footer links, and the root
  index "Spec" section.
- Dead .preview-frame CSS class (had no remaining usages).
- preview/** copy step in build-site.mjs.
- preview/** path filter in pages.yml and e2e.yml.

Adjusted:
- Chart-page placeholder note no longer links to the deleted spec
  card; says "Live render coming in the chart bundle pass." A
  follow-up commit replaces this placeholder with live rendering.
- Sparkline.test.tsx comment no longer references preview cards.

Verified: pnpm typecheck clean, 143/143 unit tests pass, build:site
emits 58 component pages (51 core + 7 charts) across 9 categories.
llms.txt unchanged (still 7.8 KB, charts section intact). No e2e
tests reference /preview/ paths (#preview locator in smoke.spec.ts
is the playground render pane).

Foundations replacement (live-rendered design tokens) and live chart
rendering are queued as separate commits in this PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replaces the hand-written brand/color/type/spacing spec cards with a
single live-rendered Foundations page. Reads tokens from
colors_and_type.css (CSS custom properties) and src/tokens.ts (type
aliases) — no hex values are hardcoded in the generator.

What the page renders:
- Color · Brand red (10 swatches)
- Color · Brand gray (10 swatches)
- Accent · semantic (--accent, --accent-hover, --accent-press,
  --accent-soft, --accent-fg)
- Surface & ink (theme-aware --bg-*, --fg-*, --border-* tokens that
  flip on data-theme switch)
- Typography · families (--font-display, --font-sans, --font-mono)
- Typography · scale (display, h1-h4, body, small, micro, code with
  live --fs/--lh/--ls values surfaced)
- Spacing scale (--space-1 through --space-24, bars rendered at the
  literal pixel value)
- Radii (--radius-xs through --radius-2xl + --radius-full)
- Shadows (--shadow-xs/sm/md/lg)
- Motion (--dur-* combined with --ease-*, animated boxes with
  Replay buttons)
- TypeScript types (every type alias from src/tokens.ts with its
  union value, sourced from extractTypeAliases)

Hex values are read at runtime via getComputedStyle so the page
mirrors the stylesheet 1:1 and the surface-token chips re-resolve
when the user toggles the theme.

Wiring:
- New renderFoundationsPage() in build-docs.mjs.
- mkdir + writeFileSync in the exec block emits
  _site/docs/foundations/index.html.
- Root index "Start here" grid promoted from 3 → 4 cards
  (Component reference, Foundations, Playground, Sample apps).
- Docs index has a top-of-page Foundations callout linking to the
  new page.
- renderSidebar prepends a Foundations entry, so component pages
  expose a quick way to jump to the tokens page.

Verified: typecheck clean, 143/143 unit tests pass, build:site emits
the new page (37.5 KB) plus the existing 58 component pages.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The chart docs pages were the last surface still falling back to a
static placeholder. They now render live in the browser, same as the
core component pages, completing the "React-only docs" goal of this
PR (no hand-written HTML left).

Approach — separate IIFE bundle:

- New scripts/bundle-entry-charts.ts re-exports `src/charts/*` plus
  React + ReactDOM's createRoot. esbuild rolls it into
  rcs-charts.iife.js as `window.RCSCharts`.
- build-site.mjs runs a second esbuild pass for this entry. Heavy
  WebGL peer deps (@deck.gl/core, @deck.gl/layers, d3-force) are
  marked --external; the chart components already have canvas2d /
  SVG fallback paths when the WebGL handoff fails to import. That
  keeps the chart bundle at ~794 KB instead of ~2.3 MB.
- The chart bundle ships its own React. Because chart demos render
  standalone in their own createRoot — never nested inside the main
  bundle's React tree — the "two React instances" footgun does not
  apply, and they read theme via CSS custom properties (not
  Context).
- esbuild also emits rcs-charts.iife.css (~1.6 KB) from the dynamic
  `await import("uplot/dist/uPlot.min.css")` in Chart.tsx. The
  chart-page <head> includes it.

build-docs.mjs:

- runner.js now exposes both `runExample` (uses window.RCS) and
  `runChartExample` (uses window.RCSCharts), refactored to share a
  `transformExample` helper. Each runner verifies its bundle is
  loaded and surfaces the failure inline.
- renderComponentPage picks the right runner via a `runFn` variable
  and conditionally injects `<script src="../bundle/rcs-charts.iife.js">`
  + the chart CSS into chart pages only.
- Static chart placeholder removed: chart pages now use the same
  `<div class="demo-render">` and a hidden code panel as core pages.
- Dead .demo-render--static / .demo-static-note CSS rules dropped.

Verified: pnpm typecheck clean, Sparkline unit tests still pass,
pnpm build:site emits both bundles (rcs.iife.js 236 KB +
rcs-charts.iife.js 794 KB) and 58 component pages. Spot-checked
generated HTML: /docs/Chart/ pulls both bundles + the chart CSS and
calls runChartExample; /docs/Button/ pulls only the main bundle and
calls runExample.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@aksOps aksOps merged commit d089049 into main Apr 28, 2026
6 checks passed
@aksOps aksOps deleted the feat/react-only-docs branch May 1, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant