Repository navigation
fix(hydration): append a rebuilt single root that was its host's last child - #1619
Merged
Merged
Conversation
… child A single-root component call that is its host element's last child, hydrated over a different server element, threw NotFoundError and left the container empty (any production compile; a development compile when the component has hooks). rebuiltAt returns null to append when the replaced node was the last child, and `?? block.endMarker` turned that into the block's end marker, which for a full single-root slot is the server node rebuiltAt had just removed. rebuiltAt now takes the block and falls back to its end marker itself, so null only ever means "append". commitBag and createHydrateSlot use it, and #1593's lite-only endMarker rewrite in adopt() is removed: the shared path now covers the lite slot too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
trueadm
marked this pull request as ready for review
October 2, 2026 23:47
…ability.insertRoot The rebuiltAt fallback added 2 B gzip to client-only bundles (commitBag), pushing root-chained-jsx past its committed budget. Move the hydrating branch of the root insert into HydrationCapability.insertRoot, which keeps an adopted server root in place and puts a rebuilt one where rebuiltAt did. commitBag and createHydrateSlot now only insert at the block's end on the client path. root-chained-jsx (production): 86002/28544/25337 on main -> 85962/28528/25335. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Benchmark report
Compares js-framework: 1k/10k row operations (ms, lower is better)All 20 timed operations (20 within noise)
Application bundle size (bytes)
7 other measured values are unchanged. Public-import reachability bundles (bytes)
48 other measured values are unchanged. |
Resolve the conflict with #1614: its rebuilt-range tail removal (rebuiltRange / takeRangeTail) now runs inside HydrationCapability.insertRoot, which replaced rebuiltAt. A null from takeRangeTail still appends. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 3, 2026
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
hydrateRootthrowingNotFoundError: The child can not be found in the parentand leaving the container blank. It happened when a single-root component call is its host element's last child and hydration rebuilds its root over a different server element.Why
HydrationCapability.rebuiltAthas three possible results:null: append, because the replaced server node was its parent's last child;undefined: the root was not rebuilt.commitBagandcreateHydrateSlotcalled it asrebuiltAt(...) ?? block.endMarker, sonullfell through to the end marker. For a full single-root slot, the end marker is the slot's anchor: the server node the template walk found, whichrebuiltAthad just removed.insertBeforethen threw.Repro (server renders the first arm, client hydrates the second):
endMarkerrewrite insideadopt().<hr>, sorebuiltAtreturned a node there.Changes
HydrationCapability.insertRoot(root, block). It keeps an adopted server root where it stands; a rebuilt root goes in place of the server node it replaced, and is appended when that node was its parent's last child; any other root goes at the block's end.commitBagandcreateHydrateSlotnow callhydration.insertRoot(...)when hydrating, and otherwise just insert atblock.endMarker. This replacesrebuiltAtand its?? block.endMarkerfallback.rebuiltRange/takeRangeTail) now runs insideinsertRoot. WhentakeRangeTailreturnsnull, the root is appended.if (block instanceof LiteBlockImpl && block.endMarker === cursor) block.endMarker = this.node;fromadopt()'s mismatch path. Every slot kind now goes through the shared path.FullLastandConstantOutputLasttotests/hydration/in-place-mismatch-full.test.ts. They run in the dev compile, the prod compile with the dev runtime, and the prod compile with the prod runtime. Each checks:<u>, and the<hr>keeps its identity;Validation
pnpm format:check: not run.pnpm format:files:checkpasses on the 4 changed files.pnpm typecheck: not run.pnpm typecheck:filespasses onruntime.ts, the test and its.tsrxfixture.pnpm test: not run locally; left to CI.NotFoundError. The dev-compile constant-output case passes on main because Fix hydration mismatch in lite component hosts #1593 patched the lite path. All 6 pass with the fix.commitBagfix fails 9 tests (lite-host-mismatchand the new cases). The shared path now protects the lite slot.octaneand 853 inoctane-prod:lite-host-mismatch,in-place-mismatch-full,root-suspended-clone-mismatch,arm-component-hole,arm-lite-hole,rebuilt-clone-order,rebuilt-clone-suspended,in-place-fragment-hole,unframed-fragment-root,in-place-component-sibling,adopted-host-component-clone,rebuilt-clone-blocks,component-range-siblings,branch-arm-tail,adopted-component-tail,deopt-host-retry,arm-hole-first-fragment,deferred-hydration,mismatch-structural,hmr.LastChildRebuild,LastChildRebuildStateandTextThenLeafRebuildpass in all three modes.node benchmarks/bundle-size/run-minimal.mjs, production raw / gzip / brotli. Last re-check after merging main 0d91b93:root-chained-jsx85,981 / 28,545 / 25,337 on main → 85,941 / 28,529 / 25,334 here (budget 86,016 / 28,576 / 25,344);--budgets root-static-local root-chained-jsx hooks-state prop-attributes contextexits 0. Earlier, against main 62e76bf:root-chained-jsx(budget enforced): 86,002 / 28,544 / 25,337 → 85,962 / 28,528 / 25,335. The first push measured 28,546 B gzip, 2 B over the 28,544 budget, which is whyinsertRootexists.--budgets root-static-local root-chained-jsx hooks-state prop-attributes context: all within budget.hydrate-root(not enforced): 169,643 / 53,945 / 47,135 → 169,637 / 53,951 / 47,062.deferred-hydration(not enforced): 233,041 / 73,828 / 63,686 → 233,011 / 73,823 / 63,748.commitBag−49 B raw / −16 B gz;createHydrateSlot−33 / −6;HydrationCapability+41 / +6;componentSlotImplunchanged.insertRootchange, re-ranin-place-mismatch-fullandrebuilt-clone-suspended(octane): 28 pass. Typecheck and format clean.in-place-mismatch-full,rebuilt-root-tailandrebuilt-fragment-suspended-child(octane): 122 pass. Typecheck clean.Risk / follow-ups
createHydrateSlotchanges only in form. A<Hydrate>wrapper always sits inside a framed range, so its server node is never its parent's last child. Probes of a last-child<Hydrate>rebuild give the same DOM before and after the change.state.anchorstill points at the removed server node. A later identity swap inside a committed Suspense boundary throws. Today that requires reassigning the live binding of an imported (cross-module) component.@ifarms: hydration replaces the arm's server markers with fresh ones.adopt()andsettleClaimnear the removed line, so a merge conflict there is possible. No logic overlaps.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches core hydration DOM commit logic (
insertRoot,commitBag,createHydrateSlot); incorrect insertion could affect mismatch recovery beyond the fixed last-child case.Overview
Fixes
hydrateRootfailing withNotFoundErrorand an empty container when hydration rebuilds a single-root component over a mismatched server node and that call is the last child of its host (no trailing sibling).Root insertion during hydration is centralized in
HydrationCapability.insertRoot(root, block), replacingrebuiltAtand the?? block.endMarkerpattern incommitBagandcreateHydrateSlot. Rebuilt roots are inserted before the following server sibling when one exists, or appended when the replaced node was the parent's last child. The previous lite-onlyendMarkertweak inadopt()is removed so all slot kinds share this path.Adds
FullLast/ConstantOutputLastfixtures and tests across dev/prod compile and runtime modes.Reviewed by Cursor Bugbot for commit 63b015b. Bugbot is set up for automated code reviews on this repo. Configure here.