Convert the render client to TypeScript with a vite-minified build - #159
Conversation
The client source js/src/* moves from concat-ordered plain JS parts to TypeScript ES modules: explicit imports/exports replace filename-order concatenation, the prototype-augmentation parts (51-57) import ChartView directly, and bytesToSpan moves 60_entries -> 00_header to keep the module graph acyclic. Typing starts pragmatic (js/tsconfig.json documents the migration posture); tsc --noEmit now gates every build. js/build.mjs keeps its CLI (node js/build.mjs / --check) but now runs tsc -> the shader-convention lint -> two vite (rolldown/oxc) builds, and the shipped artifacts are minified: static/index.js (anywidget ESM, same export surface) and static/standalone.js (IIFE; top-level var xy == window.xy). Bundle drops 389 KB -> 283 KB (~76 KB gzipped). --check byte-compares a scratch rebuild, verified byte-identical across macOS-arm64, linux-arm64, and linux-x86_64. Tests that grepped exact source lines out of the built bundles now assert them against the TS sources only; bundles are asserted via minification-surviving markers (string literals, .innerHTML counts, export aliases), with the --check freshness gate carrying source-level invariants into the shipped artifacts. CI/release jobs that build the client gain npm ci; the sdist ships js/ plus the npm manifests; CLAUDE.md and the spec amend the no-npm stance (SS33) to dev-time-only toolchain dependencies. Verified: full pytest suite (2117 passed), render_smoke_nonumpy probe matrix green against the minified standalone bundle, ruff/pre-commit clean.
Merging this PR will improve performance by 11.24%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_html_export_line |
7.7 ms | 6.9 ms | +11.24% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feat/ts-vite-client (6caeeb0) with main (a763d5f)
Footnotes
-
1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports. ↩
Greptile SummaryThis PR converts the render client to TypeScript modules and a minified Vite build. The main changes are:
Confidence Score: 5/5This looks safe to merge. No blocking issues found in the changed code.
What T-Rex did
Important Files Changed
Reviews (2): Last reviewed commit: "Invoke tsc via node, not the .bin shim, ..." | Re-trigger Greptile |
spawnSync(node_modules/.bin/tsc) is ENOENT on Windows — the shim there is tsc.cmd, which spawnSync cannot exec. Running typescript/bin/tsc through process.execPath works on every platform (caught by the windows-latest wheel job on #159).
The #159 vite-minified build mangles internal declarations, so grepping the installed bundle for 'function renderStandalone(' has failed ever since when reflex is installed. Assert on the public export names instead — they are the stable identity of the real render client.
What
The render client moves from concat-ordered plain JS parts to TypeScript ES modules, bundled and minified by vite — and the minified bundles are what ships to the client.
js/src/*.ts: real modules with explicit imports/exports (generated from the cross-file symbol graph); the ChartView prototype-augmentation parts (51–57) importChartViewand are side-effect-imported by the entry;bytesToSpanmoved60_entries→00_headerto keep the graph acyclic.git mvrenames, so blame/history follow.js/build.mjskeeps its exact CLI (node js/build.mjs/--check) but now runs tsc → shader lint → two vite (rolldown/oxc) builds:static/index.js(minified ESM for anywidget, unchanged export surface) andstatic/standalone.js(minified IIFE; top-levelvar xy=window.xy).js/tsconfig.jsondocuments the migration posture;ChartViewcarries an index-signature merge until annotated field-by-field).tsc --noEmitgates every build.Test/infra fallout
.innerHTMLcounts, export aliases, IIFE namespace props). The--checkfreshness gate is what carries source-level invariants into the shipped artifacts (rationale documented intests/test_static_client_security.py).npm ci; the sdist now shipsjs/plus the npm manifests so the client is rebuildable from source.package-lock.json); the shipped client remains runtime-dependency-free.Verification
scripts/verify_ci_workflow.pypasses.scripts/render_smoke_nonumpy.pyprobe matrix fully green against the minified standalone bundle (96.5% lit pixels, picking/selection/modebar/LOD drill, 3 context-loss cycles with identical pixel hashes).--checkrebuild is byte-identical across macOS-arm64, linux-arm64, linux-x86_64 (docker rebuilds), so the CI freshness gate holds cross-platform.node -e "import('./python/xy/static/index.js')"export-shape check andnode --check standalone.jsboth pass.Note:
uv run ty checkin a fresh venv reports ~15 pre-existing diagnostics in pyplot files byte-identical to main (env/version drift, unrelated to this change).