Repository navigation
feat(router): compile script ownership and static hydration - #2092
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.
Reviewed by Cursor Bugbot for commit 107c05b. Configure here.
Benchmark report
Compares js-framework: 1k/10k row operations
All 20 timed operations (19 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
87 other measured values are unchanged. Public-import reachability bundles (bytes)
109 other measured values are unchanged. |
trueadm
left a comment
There was a problem hiding this comment.
CI on 732550f is fully green (30/30), all 64 work counters are unchanged, and the test coverage is thorough. I'm leaving this as a comment rather than an approval for two reasons: it adds new public API that needs the owner's sign-off, and there's a small cost that every app pays.
1. executeOnMount is a new public, non-React attribute. It's typed on ScriptHTMLAttributes in jsx-runtime.d.ts, documented in docs/differences-from-react.md, and shipped as an octane minor changeset. The semantics look carefully drawn:
- static boolean only, with spreads rejected;
- HTML and DOM templates only;
- stripped from server HTML;
- adopted without replay on hydration;
- opts out of resource hoisting.
The implementation matches that description. But Octane's public surface has so far been React parity plus documented divergences, and this is the first author-facing opt-in that React has no equivalent for. React 19 leaves client-inserted scripts inert unless they're async src resources. That needs an explicit yes from Dominic before it merges. If the only consumer is Router's Scripts, a compiler-internal spelling (a __-prefixed attribute, or a directive that isn't in the public typings) would get the same lowering without committing to API.
2. Every app pays about 48 B raw / 15–19 B gzip. From the benchmark on this head (run 38757178462):
- TSRX js-framework is +48 / +14 gzip, todo/chat/weather +48 / +16–18, Threadline and Pagecraft +48 / +13–19.
- JSX
jsis +48 / +14. - All reachability roots (
hooks-state,root-static-local,component-owned-effects…) are +48 / +15–19. full_fwis +643 / +179, which comes from the new exports.
The +48 comes from the uniform prepare: null field in every template() record (runtime.ts ~21232) and the lazy.prepare !== null test in resolveLazyTemplate. Only scriptTemplate uses them. The amount is under what I'd block on, but it's paid by apps that never render an executable script.
Could scriptTemplate own its preparation instead? For example, it could return a token whose record resolves through its own path. Or the hook could be a driver that scriptTemplate installs and resolveLazyTemplate reads by truthiness. I'd keep the shape stability you get from always initializing the field, but put it on a record that only scriptTemplate creates. Separately, the body's own isolated measurement (ordinary Router +2,109 gzip, compiled Router −1,149) deserves a line on which real consumers take the ordinary entry, since that's a large step for them.
Correctness notes (none blocking):
scriptTemplate'sprepare(runtime.ts~21240) callsview.setAttributeNS(attr.namespaceURI, attribute.name, attribute.value). That mixes the rawattrwith the stagedattributeview. Useattribute.namespaceURIso the staged-DOM path reads consistently.- Execution order. Router's managed external scripts that carry
executeOnMountbut noasyncwill execute in arbitrary order. A script created bycreateElementand then cloned inserts as force-async. That's the same as the old descriptor path, so it's not a regression. If upstream relies on ordering between<script src>entries, though, the docs line "async ordering still follow[s] the browser's rules" undersells it: the force-async flag isn't carried acrosscloneNode, so fixing it on the cached source wouldn't help. A test or a docs sentence stating that sibling external scripts are unordered would settle it. - Runtime spreads. The spread rejection only catches statically visible object literals. A runtime spread containing
executeOnMount(for example, ifscript.attrsever carried one) would fall through tosetAttribute('executeonmount', …). That's harmless but worth a dev warning. ScriptOnce/CompiledScrollRestoration. Moving these to<Hydrate split={false} when={never()}>withtrustHTMLreuses the existing permanent-static range. Importing__PermanentStaticHydratedirectly so static-only consumers don't retain deferred activation is a good find, and the Vite/esbuild hydration-free gate now pins it.
What I'd need in order to approve:
- Dominic's decision on (1): either keep
executeOnMountpublic, with the docs and changeset as written, or make it compiler-internal. - For (2): the per-app +48 B gone through a template record or driver that only
scriptTemplatecreates, or a measured reason it has to stay. - The
setAttributeNSview fix.
Reviewed with Claude Code
|
Addressed on signed head
Final-source website hydration/navigation and preboot scroll match main in development/production at desktop/narrow widths; focused tests, source/public typing checks, Strong analysis and staged DOM checks pass. Current-head CI passes all 27 jobs, including 105 website and 620 Chromium tests and both Router-reaching parity lanes. The benchmark confirms all 13 complete application-JavaScript gzip metrics and all 64 work counters are unchanged. It flags one of 20 timed operations slower ( |

Summary
Continue #2059 by compiling Router’s shared script owner and server-only scroll-restoration range without changing their lifetime. Fresh route scripts execute on client navigation; existing server scripts are adopted without replay; self-removing Start transport leaves no stale item frame.
A literal cloned script template is inert on navigation. Router now uses a Strong keyed host template with a compiler-internal
__executeOnMountmarker; it is not a public JSX option. Only those script tokens prepare executable sources on the first parsed cache read for each namespace. Ordinary template records, their factory and resolver retain main’s layout and path. Runtime-provided Router attributes cannot forward the reserved marker. The scroll script uses the existing permanent-static hydration range, and static-only client lowering avoids retaining deferred activation code. Router and its SSR-query dependent explicitly select Octane’s TSRX type compiler in their Octane-owned programs, preventing mixed React/Octane dependencies from selecting React’s projection. Pristine React comparison programs retain their compiler.Validation
pnpm format:check— scoped changed-file formatting passes locally; the full gate passes in current-head CI.pnpm typecheck— affected source/public typing programs pass locally; the full gate and both Router-reaching adapted parity lanes pass in current-head CI.pnpm test— current-head sharded CI and separate website/browser integration lanes pass; no monolithic full-workspace local run is claimed.3691ea2busing the same Chromium harness and dependency graph. All 24 paired hydration/navigation journeys and eight paired preboot scroll cases pass across desktop/narrow viewports. After the Router type-compiler configuration fix, the website rebuilt with all 614 public JavaScript files and four Lynx containers byte-identical to the browser-tested output; the later SSR-query follow-up changes only its type configurations and audit metadata. Original document/shell and script nodes are adopted; route transitions, history, controls and preboot 610px scroll restoration behave as on main. Existing Lynx teardown diagnostics and deliberate 404s match main; no request failures occurred. Narrow viewport is emulation, not physical-device or deployed-site proof.pnpm sync; independent read-only complexity/performance review found no must-fix findings.Current-head CI passed all 27 jobs on signed
86a051348, including the Router and SSR-query parity shards, 54,421 general tests (two skipped), 105/105 website tests, 620/620 Chromium tests, types, lint, publication, examples and bundle gates. Bugbot passed with no new findings. The current-head benchmark passed: all 64 work counters and all 13 complete application-JavaScript gzip metrics are unchanged. The full-export framework fixture grows 775 raw / 213 gzip bytes, and three deferred/split reachability fixtures grow 6–10 gzip bytes. One of 20 paired timings, TSRXselect_lots, is flagged slower (+8.6%, 95% CI +6.6% to +10.5%; raw averages 0.005541 → 0.006200 ms); the other 19 are within the report’s noise threshold. Independent source review found no changed selection mechanism in that fixture, but the timing difference remains unexplained; this is not a speed-equivalence claim.Risk / follow-ups
deferdo not serialize their execution. An inserted hidden primary may execute before a later sibling suspends, as with the prior descriptor owner.<Scripts />with scroll restoration. Their exact application deltas were not measured. The Octane website explicitly selects the compiled entry./benchmarksin dark mode. The test and inspected animation sources match main, eight matched local main/candidate probes passed, and the final-head website lane passed unchanged; the original timeout’s exact cause remains unknown.compiled/Matches.tsrx, RouterlinkBinding.ts, Threeweb/events.ts, broader descriptor elimination and final package-level enforcement remain under Run the website in Strong mode #2059.Provenance
agent-authored)Codex task · implementation host
com-79386.Need help on this PR? Tag
@codesmith-botwith what you need.Note
Medium Risk
Changes script execution semantics, hydration adoption, and Router SSR/client navigation paths; mistakes could cause double execution, skipped scripts, or broken scroll restoration.
Overview
Adds a compiler-only
__executeOnMountflag on native<script>templates so opted-in scripts usescriptTemplate(live document scripts on clone) while ordinary templates stay inert. Volar strips the marker from public DOM typing; spreads and non-DOM renderers are rejected.Permanent-static hydration now renders via exported
__PermanentStaticHydratewith a direct import, so client bundles can drop deferredHydrateactivation code; bundle benchmarks add apermanent-staticscenario to enforce that. Range preservation no longer assumes an active hydration pass when skipping.TanStack Router moves route scripts to Strong keyed templates with mount execution, strips caller-supplied
__executeOnMountfrom runtime attrs, and wraps scroll-restoration /ScriptOnceoutput in permanent-static ranges (server HTML adopted, scroll script removed after hydration). Router tsconfigs pinoctane/compiler/volarfor TSRX typing. Start/document hydration tests assert script adoption, input retention, and no duplicate script insertion.Docs, status notes, and broad compiler/browser tests cover execution vs replay, CSP nonces, and external script ordering.
Reviewed by Cursor Bugbot for commit 86a0513. Bugbot is set up for automated code reviews on this repo. Configure here.