Skip to content

fix: stop the compiled @for path retaining the descriptor renderer - #767

Merged
domgan-oai merged 1 commit into
mainfrom
fix/deopt-body-identity-reachability
Aug 16, 2026
Merged

domgan-oai merged 1 commit into
mainfrom
fix/deopt-body-identity-reachability

Conversation

@trueadm

@trueadm trueadm commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

mountItem decided whether a de-opt list's items render through the plain
deoptItemBody by comparing the body function by identity. The comparison is
correct and cheap, but mountItem is on the compiled @for mount path that
every list-rendering application reaches, so naming deoptItemBody from it is a
live reference a bundler must honour. Retaining deoptItemBody retains
childSlot — the universal renderable-hole dispatcher — and through it the
descriptor renderer, FragmentInstance and fragment refs, portals, transitions,
controlled-form restoration, focus preservation and the DOM attribute tables.
Applications that only ever render compiled templates, and never present a
generic renderable hole, shipped all of it.

The fact is now recorded on the ForSlot as plainDeopt, alongside the existing
mappedNative flag, and stamped by childSlot where the body is chosen — inside
the graph that already retains those modules. mountItem reads the flag instead
of naming the function.

The recorded value is exactly the identity test it replaces. Within the de-opt
branch the body is deoptItemBody precisely when the compiler supplied no map
body and this is not the mapped fallback, because both body-wrapping assignments
above it are guarded by those same two conditions:

  • the compiledMapBody !== undefined wrapper cannot apply when there is no map
    body, and
  • the markerlessMappedFallback wrapper implies mappedFallback === true.

Both ForSlot literals declare the field, so every slot keeps one hidden class
and the stamp transitions nothing.

Where this came from

Bisected to 4c1ecd143 ("Float style resources and the Context.Consumer
decision made concrete", #712, 12 Aug), which introduced the identity tests.
Same app source and build config throughout, only packages/octane/src varying:

commit date js-framework rows, gzip
a1d506777 08-09 17,639
d2c9e1ca9 08-10 19,880
a03ff0f33 08-11 20,227
4c1ecd143 08-12 40,428
48fa46cdc 08-16 40,499

runtime.ts grew 9% over that window while the rows bundle grew 147%, so this
was reachability, not code growth.

Changes

  • packages/octane/src/runtime.ts — record ForSlot.plainDeopt in childSlot;
    read it in mountItem instead of comparing against deoptItemBody; declare
    the field in both ForSlot literals.
  • packages/octane/tests/hydration/mapped-fallback-hydrate.test.ts +
    _fixtures/mapped-fallback-list.tsx — new coverage for the mapped-fallback
    hydration path, which had none.
  • benchmarks/bundle-size/app-budgets.json,
    benchmarks/bundle-size/minimal-budgets.json — re-record the ceilings this
    change moves. Tightened only; nothing is loosened.

Results

Normalized production builds, gzip, via benchmarks/bundle-size/run.mjs:

application before after delta
js-framework rows 40,752 20,609 −49.4%
TodoMVC 41,293 21,835 −47.1%
chat-stream 41,530 21,968 −47.1%
weather-app 49,524 31,742 −35.9%

benchmarks/bundle-size/run-minimal.mjs: cli-spa-starter — the entry
octane init generates — drops 40,362 → 23,903 gzip (−40.8%).

The saving is entirely in the framework chunk (rows 38,380 → 18,237 B). Every
application chunk is byte-identical, because no compiler output changed. The rows
bundle drops from 559 surviving top-level declarations to 340: childSlot,
FragmentInstance, deoptItemBody, renderPortalState, startTransition,
setAttribute and attachLiveFragmentRef all become unreachable, while
reconcileKeyed and mountItem correctly remain.

Validation

  • pnpm format:check — clean.
  • pnpm typecheck — clean.
  • pnpm test — 21,759 / 21,761 passed. The two failures are both
    packages/octane/tests/browser/native-change/native-change.test.ts, failing on
    Failed to load resource: 504 (Outdated Optimize Dep) — a Vite dependency-
    optimizer race on this fresh worktree's first browser run, not an assertion
    about behavior. Re-running that file alone passes 12/12.
  • targeted tests: hydration/descriptor-list-hydrate, hydration/map-hydrate,
    hydration/mapped-fallback-hydrate, deopt-item-selfmark,
    deopt-item-path-switch, plus the whole tests/hydration directory and the
    deopt-* / descriptor-children files.
  • benchmarks/bundle-size/run.mjs and run-minimal.mjs, Node 24 (the pinned
    CI version), before and after.

Mutation-checked rather than assumed: forcing plainDeopt to the inverse, and
separately to a constant false, turns 18 tests in
hydration/descriptor-list-hydrate.test.ts red. See the coverage note below for
the direction that is not pinned.

Risk / follow-ups

  • Untested direction. Forcing plainDeopt to a constant true passes all
    730 tests in tests/hydration + the deopt-* files, and passes the new
    mapped-fallback test. I could not construct a case where the true direction
    is observationally different: for pure host items the third disjunct at each
    read site rescues it, and for component items the fall-through is the marked
    path that is correct anyway. The equivalence argument above is what carries
    that direction, not a test. Worth a second opinion.
  • Suspend-closure staleness. mountItem re-invoked through
    hydration.suspend re-reads forSlot.plainDeopt rather than a captured value,
    where it previously used the captured body. For the value to differ, the same
    for-slot would have to re-render with a flipped native/fallback verdict between
    the suspension and its resumption — at which point the captured item and the
    slot's markers are already inconsistent, so this is not a new risk class. Not
    covered by a test.
  • octane-jsx remains 1.17× over its committed framework ceiling (38,975 vs
    33,344 gzip) and this change does not move it. The JSX dialect legitimately
    reaches the descriptor renderer, so it is exposed to that graph's real growth
    over the same 08-10 → 08-13 window. I did not diagnose it and deliberately did
    not raise jsx-budgets.json; it needs its own investigation.
  • TodoMVC's application ceiling stays exceeded (2,199 vs 2,112 gzip). The app
    source is unchanged since the ceiling was recorded on 08-08, so this is
    compiler-output growth from that window. It is unrelated to this change — the
    app chunk measures 2,198 B before and 2,199 B after — and I left the ceiling
    alone rather than bless it.
  • Several bundle-reachability ceilings stay exceeded (hydrate-root,
    deferred-hydration, suspense-transition, server-render, capture-only,
    the binding-* scenarios). All were already over before this change; they
    reach childSlot through the general-root path, which this fix does not touch.
    Left as a true signal rather than re-recorded.
  • The separate architectural finding stands. root-static-specialized ships
    12,285 B gzip against root-static's 36,434 B: escaping compiler-proven root
    specialization still costs ~24 KB in one step, because childSlot is a runtime
    dispatcher rather than a set of compiler-injected entry points. That is a
    design change, not a fix, and is out of scope here.

Provenance

  • An agent produced this diff (agent-authored)

Note

Medium Risk
Touches core list mount/hydration (mountItem, SSR markerless paths) with equivalence argued but one direction of plainDeopt not fully mutation-tested; behavior should match prior identity checks.

Overview
Compiled @for lists no longer pull the full descriptor renderer into every app bundle by avoiding a deoptItemBody identity check on the hot mountItem path.

ForSlot gains a plainDeopt flag (set in childSlot when there is no compiled map body and the list is not on the mapped-fallback path). mountItem and related hydration branches read that flag instead of comparing body === deoptItemBody, so bundlers can drop childSlot and the descriptor graph for apps that only use compiled templates. Both ForSlot object literals initialize the field for a stable hidden class.

Bundle-size budgets in app-budgets.json and minimal-budgets.json are tightened to match roughly ~50% smaller framework gzip for sample apps. New mapped-fallback hydration tests ensure exotic items.map arrays still adopt server DOM and stay keyed after reorder.

Reviewed by Cursor Bugbot for commit e24b3a7. Bugbot is set up for automated code reviews on this repo. Configure here.

`mountItem` decided whether a de-opt list's items render through the plain
`deoptItemBody` by comparing the body function by identity. `mountItem` sits on
the compiled `@for` mount path that every list-rendering application reaches, so
naming `deoptItemBody` from it is a live reference a bundler must honour, and
retaining it retains `childSlot` — and through it the descriptor renderer,
fragment refs, portals, transitions, controlled-form restoration, focus
preservation and the DOM attribute tables. Applications that only render
compiled templates shipped all of it.

Record the fact on the `ForSlot` as `plainDeopt`, stamped by `childSlot` where
the body is chosen — inside the graph that already retains those modules — and
read the flag in `mountItem` instead. The value is exactly the identity test it
replaces: within the de-opt branch the body is `deoptItemBody` precisely when
the compiler supplied no map body and this is not the mapped fallback, because
both body-wrapping assignments are guarded by those same two conditions. Both
`ForSlot` literals declare the field so every slot keeps one hidden class.

Normalized production gzip: rows 40,752 -> 20,609, TodoMVC 41,293 -> 21,835,
chat-stream 41,530 -> 21,968, weather-app 49,524 -> 31,742, and the CLI-generated
starter 40,362 -> 23,903. No compiler output changed, so every application chunk
is byte-identical; the saving is entirely framework reachability. Budgets are
re-recorded for the ceilings this moves, tightened only.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants