From ff5ebd723cf804065a57b5af8bfeefe85f116b97 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 28 Apr 2026 16:04:33 +0000 Subject: [PATCH] perf(docs): pre-transform demo JSX at build time, drop Babel-standalone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Component and chart docs pages were each pulling `@babel/standalone@7.29.0/babel.min.js` from unpkg (~600 KB) just to transform a handful of JSX strings already known at build time. The @example blocks in src/components.ts and the chart demo literals are all static — the browser was redoing work the build pipeline could trivially do once. Approach: - New `compileDemo(jsxCode)` helper in build-docs.mjs uses esbuild's transformSync (already a dev-dep for the IIFE bundle) with the classic JSX runtime targeting `React.createElement` / `React.Fragment`. Both identifiers are bound in the runner factory via `var { React, Button, ..., createRoot } = R`, so the transformed JS evaluates without any further setup. - renderComponentPage now feeds runFn(...) the *compiled* string per demo. The visible code panel and copy-button still receive the original JSX via DEMO_CODES — same UX, same source-of-truth. - runner.js dropped the Babel.transform pass and its readiness check. The two run* helpers now eval the pre-transformed factory directly. The per-page readiness gate switched from `window.RCS && window.Babel` to just the bundle global appropriate for the page (window.RCS or window.RCSCharts), since there is no JSX compiler to wait on. - The `${chart ? ` ` : ""} - `;