Repository navigation
fix(hydration): activate ready independent islands one per task - #1866
Merged
Merged
Conversation
Independent islands that become ready together (repeated instances sharing one module, one stylesheet load or IntersectionObserver callback, a back/forward-cache restore) each hydrated synchronously in the same microtask checkpoint, so input and paint waited for all of them. `registerIndependentHydrationIsland` now passes each activation through a per-document gate after the module resolves and before replays are taken. The first island to arrive in a task activates at once; each later one gets its own task (scheduler.postTask, then MessageChannel, then setTimeout), and islands holding captured input go first. A waiting island is still loading: input keeps joining its replay queue, pause and dispose cancel it without using up a task, and the native-intent expiry filter runs after the wait. Step 4 of #1864. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 7, 2026 21:24
This was referenced Oct 7, 2026
Contributor
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)No changes across 60 measured values. Public-import reachability bundles (bytes)No changes across 111 measured values. |
Collaborator
Author
No code change for the benchmark report's
|
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
This is step 4 of #1864, from the investigation comment. Independent
<Hydrate>islands that become ready together now activate one per task, not back to back in one microtask checkpoint.Why
Each island activation (
adopt→renderBlock→commitRootRenders) is one synchronous block. Ready islands used to activate back to back inside one checkpoint, so the browser could not deliver input or paint until every one of them had finished. These paths converge in practice:loadevent;IntersectionObservercallback with the default600pxmargin, releases several islands together;pageshow→resume()re-arms every unfinished island in one loop, and their modules are already evaluated.Changes
registerIndependentHydrationIslandsends each activation through a per-document gate inactivate. The gate sits after the module resolves and beforeintents.splice(0)/replayReady = true. It lives in this public function rather than in app-core codegen, so custom hosts that call the function directly get it too.scheduler.postTaskif present, otherwise a one-shotMessageChannel, otherwisesetTimeout.replayReadystays false, so input keeps joiningintents. Setting it before the yield would send input to a hold the activator has not registered yet, and the input would be dropped.activelatch prevents a second chain.pause()and dispose still cancel. After the wait,runre-checksdisposed || generation !== attemptand then runs the native-intent expiry filter.onError, and the next island still gets its turn.docs/deferred-hydration.mdgains an "Activation pacing" subsection.docs/ssr.md(islands-only routes) links to it.octanepatch.Not done: forwarding the
IdleDeadline. The brief marked it optional, and I left it out:requestIdleCallbackcallback already runs as its own task;Pacing within an idle period belongs to the shared host budget (G3).
Validation
New:
packages/octane/tests/hydration/independent-island-activation-pacing.test.ts(5 tests).MessageChannelordering. Fourloadislands share one module. AMessageChanneltask is armed before the module resolves. The first island hydrates in the readying task, and the armed task runs before the last island hydrates.scheduler.postTaskis stubbed to hold tasks, which makes this deterministic. Exactly one island activates per task, and theinteractionisland with a captured click goes ahead of earlierloadislands. A second click on that island while it waits is replayed (intents=click, click).onError, and the next island still activates.pagehidebefore the modules resolve, thenpageshow: the restore resumes three islands, and they activate one per task.Mutation checks: each one turned the named tests red.
replayReadyset before the yieldrunExisting island suites (unchanged): 11 files and 271 tests pass in
--project octane. They are the new file plusindependent-island,independent-island-strategies,document-lifecycle,early-independent-intent,early-control-handoff,independent-parent,independent-root-fallback,deferred-hydration-styles,independent-island-signal-identity, andform-submission.initial-document-signalspasses in--project octane-signals(38).pnpm typecheck:fileson the changed source and testpnpm format:files:checkon every changed file;pnpm syncwas cleanpnpm format:check,pnpm typecheck,pnpm test: not run locally. The machine is shared, so CI runs the full suites.Bundle cost: esbuild minify of
hydration/independent-island.tswith the strategies chunk external goes from 20,845 to 21,539 B minified (+694) and from 7,531 to 7,790 B gzip (+259). Only pages that register independent islands load this chunk, and no bundle-size budget covers it.Risk / follow-ups
awaitis not paced for that later work. The in-repo activators (createIndependentHydrateActivator, the dom-binding island activator) are synchronous.runtime.ts.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes core independent-island activation timing on the client hydration path; incorrect pacing could delay interactivity or mishandle captured input, though behavior is covered by new tests and preserves existing pause/dispose semantics.
Overview
Independent
<Hydrate>islands that become ready in the same microtask checkpoint (shared module load, one stylesheetload, IO callback, or bfcacheresume) no longer hydrate back-to-back in one synchronous stretch.registerIndependentHydrationIslandnow routes post-module activation through a per-document gate: the first ready island still runs immediately in that task; each additional island waits for its own task viascheduler.postTask,MessageChannel, orsetTimeout(0).Islands with captured interaction intents are scheduled ahead of automatic
load/idle/visible triggers. While an island waits, it stays in the loading path (replayReadystays false) so input keeps appending tointents; pause, dispose, and stale attempts skip without consuming a turn. Activator errors still hitonErrorand the queue advances.Docs add an Activation pacing subsection under deferred hydration and link it from islands-only SSR notes. A new Vitest suite exercises task ordering, input priority, pause/dispose/resume, errors, and bfcache restore.
Reviewed by Cursor Bugbot for commit 5772fef. Bugbot is set up for automated code reviews on this repo. Configure here.