Repository navigation
fix: preserve context tracking when retained subtrees become memoized - #1977
Conversation
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
31 other measured values are unchanged. Public-import reachability bundles (bytes)
88 other measured values are unchanged. |
|
Good to go, with two small nits. The root cause is fixed. Suggestion (not blocking): the memoWrapper guard runs on every memo render. if (taggedChildren && !wasImplicitlyArmed) state.block.$$implicitBail = true;
if ((taggedChildren || (comp as any).__memo === true) && !state.block.memoInChain)
promoteMemoAncestry(state.block);Nits:
Verified:
|
Summary
Keep retained context consumers reactive when an existing ancestor gains a memo or compiler-cached child boundary.
Why
The descendants were created before that boundary existed. Marking only the ancestor left their
memoInChainflags false, so later context reads skipped dependency recording. Changing the provider then left stale text.The fix promotes existing descendants when the boundary is armed. It covers a lazy body becoming memoized, an ordinary render function becoming cached compiled children, and a memo wrapper taking over a retained render slot.
Changes
Validation
5d6d02c8, the four new context scenarios fail in both development and production: 8 expected failures, with 4 neighboring controls passing.pnpm syncpass with no generated changes.perf-review:node scripts/perf-review-scan.mjs --base 2075c0e7 --head HEAD --jsonreports 0 candidates.memoWrapperadds a per-render guard;promoteMemoAncestryvisits retained scopes only when a boundary is newly armed. It writes an existing boolean field and adds no collection, closure, DOM operation or scheduling hop. Compiler sources and ancestry loops are unchanged. The current-head benchmark report passes with all 64 work counters unchanged; local latency is unmeasured.concise-code: source/runtime +29 −7; no new source file or export. The new changeset records the correctness fix. Reusing the ancestry flag and subtree visitor preserves state; remounting would lose it, while recording every context read would tax ordinary trees without memo boundaries. The report measures +34 B gzip for the complete root-static fixture, +62 B for weather production JS and +84 B for bindings production JS; these are correctness-fix costs, not size savings.f991f5329against2075c0e7: 12/12 focused development/production checks pass; fullpnpm syncpasses with no generated changes. The promotion patch remains +29 −7; the compiler and existing context walks match main.f991f5329pass, including full CI and the benchmark report. Maintainer review is still required.Risk / follow-ups
Promotion walks a retained subtree only when its boundary is newly armed; the memo wrapper also gains a small guard. Existing context ancestry walks are unchanged, and no block field, cache or compiler transform is added. Local latency has not been measured, and no speedup or Ripple parity is claimed. Timing the stale-output baseline would not compare equivalent behavior.
This is the context correctness change separated from #1967. The descriptor optimization, shorter context walks and teardown optimization are excluded.
Provenance
agent-authored)Codex task · implementation host
com-79386.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Touches core runtime context dependency tracking in memo, lazy, and implicit-bailout paths; behavior is narrowly scoped to newly armed boundaries but affects re-render correctness.
Overview
Fixes stale context when a retained subtree’s ancestor later becomes a
memo()boundary or compiler-cached child slot: descendants created earlier keptmemoInChainfalse, souseContextskipped dependency recording and provider updates did not re-render them.Adds
promoteMemoAncestry, which walks the retained block/scope subtree and setsmemoInChainwhen lazy resolution, implicit bailout arming, or the owningmemowrapper first arms the boundary—instead of only flipping the ancestor block.memo()now promotes only when the current render scope actually owns that wrapper, so direct calls outside a boundary stay safe.Regression coverage spans lazy→memo promotion, render-function→compiled-children, memo→element, suspension rollback, and preserved DOM/input identity; changeset records an octane patch.
Reviewed by Cursor Bugbot for commit f991f53. Bugbot is set up for automated code reviews on this repo. Configure here.