Repository navigation
perf(octane): load independent idle/visible/media strategies on demand - #1681
Merged
Merged
Conversation
The independent island bootstrap statically imported idle(), visible() and media() to rebuild a wrapper's serialized `when`, so every islands page shipped all three even when its widgets used only load() and interaction(). The decoding now lives in octane/hydration/independent-strategies. The bootstrap and registerIndependentHydrationIsland accept it as `strategies`, which arms triggers during registration exactly as before. When it is omitted, an island that needs a trigger imports the strategies on demand and arms once they resolve, honoring dispose and pause in between and reporting a failed load or arm through onError. The four parameter attribute names move to a leaf module so the strategies chunk shares no module with the bootstrap; sharing hydration-markers split it into an extra chunk every islands page loaded. signal-chat islands-only route: 71,763 -> 71,151 B gzip-9, 18 scripts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 3, 2026 19:06
Contributor
Benchmark report🟢 No budget breaches, no added work, and no timing changes beyond ±3%. Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
50 other measured values are unchanged. Public-import reachability bundles (bytes)No changes across 105 measured values. |
trueadm
added a commit
that referenced
this pull request
Oct 3, 2026
Main gained #1685, which raised 51 budgets for the useLayoutSnapshot commit-phase priority fix (#1686), and #1681/#1665. Re-measured on main 425a32a: each of #1663, #1664 and #1666 merged alone, and all three plus #1686 merged together. Each budget is the larger of main's value and the largest measured value plus 32 (raw/gzip) or 256 (brotli), so the three perf PRs and #1686 can land in any order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The independent island bootstrap (
packages/octane/src/hydration/independent-island.ts) statically importedidle(),visible()andmedia()to rebuild a wrapper's serializedwhen. Every islands page therefore shipped all three, including pages whose widgets use onlyload()andinteraction(), such asexamples/signal-chat.Result: the signal-chat islands-only route drops from 71,763 B to 71,151 B gzip-9 (−612 B), still 18 scripts. That baseline is d826c3e, before #1678 (signal Action frame) landed. The branch now includes #1678, which measured the same route at 67,719 B and set a 68 KiB cap. The combined route is not measured locally; CI's islands budget e2e runs it against that cap.
What changed
octane/hydration/independent-strategiesexportsindependentHydrationStrategies. It holds the attribute decoding thatautomaticStrategydid, and it is now the only module that imports idle/visible/media.strategiesoption onbootstrapIndependentHydrationandregisterIndependentHydrationIsland:independent-island-strategies.test.tspins.whenis idle, visible or media imports the strategies on demand and arms once they resolve. Dispose and pause during the load are honored. A failed load, or a failed arm such asmatchMediathrowing, goes toonError, as a synchronous arm failure did before.hydration-markers.tsto a leaf module,hydration/strategy-attributes.ts. Only the server and the strategies chunk use them. If the strategies chunk shares any module with the bootstrap graph, the bundler splits that module into a separate chunk, and every islands page then loads it. Sharinghydration-markersmeasured +329 B plus one extra script.packages/app-core/src/codegen.jspasses nostrategies, so its pages use the on-demand path.Why no preload in the generated entries
I measured an alternative in which the entries scan the initial DOM for idle, visible or media sidecars and await the strategies before calling the bootstrap:
hydrationchunkThe preload made every renderer page pay about 111 B, including pages with no islands. It also delayed
load()islands behind the strategies chunk. A failed chunk load rejected the whole bootstrap, so eveninteraction()islands stopped registering. And it bought nothing an app can observe: an idle, visible or media island cannot arm before the chunk arrives in either design.Reviewer notes
Promise.all([import('octane/hydration'), …]).then(([{ … }]) => …)hides the destructuring from the bundler. The full entry then keeps the wholeoctane/hydrationnamespace, which reshuffled shared chunks and grew the islands page to 75,351 B. Onlyimport(x).then(({ a }) => …)or.then((m) => m.a)stays tree-shakeable.docs/deferred-hydration.mddescribes the on-demand load and thestrategiesoption. The changeset isminorbecause it adds a new public subpath and option.Validation
Per-chunk bytes for the islands-only page, baseline vs this PR, gzip-9 of the scripts the page loads:
hydration−535,data-encoding−58,event-capture−20; every other chunk within ±9 B.The full entry,
octane-hydrate, is unchanged (2,328 → 2,329).pnpm format:files:checkon the changed filespnpm typecheck:fileson the changed files (clean); fullpnpm typecheckwas not run locallypnpm test(full suite not run locally; left to CI)targeted tests:
packages/octane/tests/hydration/independent-island-strategies.test.ts: 12 pass. The existing cases now passstrategies. New cases cover arming on demand, dispose and pause before the load resolves, and an arm failure reachingonError. Five deliberate code breaks each failed the matching test, including one that ignores a passedstrategiesand fails the synchronous-arming cases.independent-island.test.ts,-signal-identity,early-independent-intent, andindependent-parentall pass, 120 tests across the five files.packages/vite-plugin-octane/tests/islands-route.test.ts: a real Vite production build now also asserts that the five strategy modules stay out of the islands bootstrap's static graph. A control checks they are still emitted. Re-adding a static import of the strategies fails it.examples/signal-chat:pnpm build, then theislands-only JavaScript budgete2e against the production preview, passes at 71,151 B (baseline 71,763 B on d826c3e).node benchmarks/bundle-size/run-minimal.mjs --budgetsandbenchmarks/bundle-size/run.mjspass.hydrate-root,deferred-hydrationandcapture-onlyare byte-identical to the baseline.Risk / follow-ups
strategies: independentHydrationStrategies.hydrationchunk's namespace object containsSTREAMED_RENDERER_RECEIVER: () => STREAMED_RENDERER_RECEIVER, but that identifier isn't declared in the chunk. It is also present on main, and nothing reads that property.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Low Risk
Bundle-size and lazy-loading change for independent hydration; behavior is covered by expanded tests, with only a slight delay before idle/visible/media islands arm when
strategiesis omitted.Overview
Independent island bootstrap no longer statically pulls in
idle(),visible(), andmedia(). Those triggers live in a newoctane/hydration/independent-strategieschunk (independentHydrationStrategies), loaded the first time a registered widget needs one; islands pages that only useload()andinteraction()skip that JavaScript (e.g. signal-chat islands route −612 B gzip).bootstrapIndependentHydrationandregisterIndependentHydrationIslandaccept an optionalstrategiesoption to arm triggers synchronously during registration (same behavior as before). Generated app entries omit it and use the on-demand path. Strategy parameter attribute names moved tohydration/strategy-attributes.tsso they are not shared with the bootstrap graph and forced into every islands entry.Reviewed by Cursor Bugbot for commit 6951daf. Bugbot is set up for automated code reviews on this repo. Configure here.