Skip to content

Commit 24d150b

Browse files
committed
fix(octane): keep source-plan miss counts off host elements
Store the planned-diff miss counter on the committed resolved record next to SOURCES_PLAN, and copy it onto replacement records so poison still survives, instead of writing a hot-path DOM expando.
1 parent 4dacf01 commit 24d150b

2 files changed

Lines changed: 57 additions & 15 deletions

File tree

‎packages/octane/src/runtime.ts‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24015,11 +24015,12 @@ function resolveHostPropSources(
2401524015

2401624016
const SOURCES_PLAN = /* @__PURE__ */ Symbol('octane.host-prop-sources-plan');
2401724017
/**
24018-
* Consecutive failed plan verifications after which an element stops paying
24018+
* Consecutive failed plan verifications after which a host stops paying
2401924019
* attachSourcesPlan's per-commit allocations — a source shape that never
24020-
* stabilizes reverts to the full path for good. ponytail: poisoned is
24021-
* permanent; a shape that stabilizes later keeps the full path (reviving it
24022-
* would take a decay or per-shape plans).
24020+
* stabilizes reverts to the full path for good. Lives on the committed
24021+
* resolved record beside SOURCES_PLAN, never on the DOM node. ponytail:
24022+
* poisoned is permanent; a shape that stabilizes later keeps the full path
24023+
* (reviving it would take a decay or per-shape plans).
2402324024
*/
2402424025
const SOURCES_PLAN_MISSES = /* @__PURE__ */ Symbol('octane.host-prop-sources-plan-misses');
2402524026
const SOURCES_PLAN_MISS_LIMIT = 3;
@@ -24387,7 +24388,7 @@ function writePlannedDiff(
2438724388
* record to commit (`prev` itself when nothing changed) or null when there is
2438824389
* no plan, hydration is active, the shape changed, or signal handles appear —
2438924390
* the caller then takes the full path. Failed verifications count toward
24390-
* SOURCES_PLAN_MISS_LIMIT, after which the element stops paying
24391+
* SOURCES_PLAN_MISS_LIMIT, after which the host stops paying
2439124392
* attachSourcesPlan's allocations entirely.
2439224393
*/
2439324394
function replaySourcesPlan(
@@ -24399,14 +24400,14 @@ function replaySourcesPlan(
2439924400
readStyle: ((value: unknown) => unknown) | undefined,
2440024401
): Record<string, unknown> | null {
2440124402
if (activeHydration() !== null) return null;
24402-
const plan = (prev as Record<symbol, unknown>)[SOURCES_PLAN] as ResolvedSourcesPlan | undefined;
24403+
const tagged = prev as Record<symbol, unknown>;
24404+
const plan = tagged[SOURCES_PLAN] as ResolvedSourcesPlan | undefined;
2440324405
if (plan === undefined) return null;
2440424406
if (!scanSourcesForPlan(sources, plan, prev, readStyle)) {
24405-
const tagged = el as any;
2440624407
tagged[SOURCES_PLAN_MISSES] = ((tagged[SOURCES_PLAN_MISSES] as number | undefined) ?? 0) + 1;
2440724408
return null;
2440824409
}
24409-
(el as any)[SOURCES_PLAN_MISSES] = 0;
24410+
if (tagged[SOURCES_PLAN_MISSES]) tagged[SOURCES_PLAN_MISSES] = 0;
2441024411
const next = buildFromSourcesPlan(plan, prev);
2441124412
if (
2441224413
next === prev &&
@@ -24636,14 +24637,17 @@ export function setHostPropSources(
2463624637
// allocations. The plan stamps the record actually retained — on an
2463724638
// unchanged commit resolvedHostPropsEqual just proved `prev` carries the
2463824639
// identical keys, so the plan replays correctly against it — rather than
24639-
// dying with a discarded `resolved`. Elements whose scans keep failing stop
24640-
// paying the attach once SOURCES_PLAN_MISS_LIMIT trips.
24641-
if (
24642-
!formHost &&
24643-
prev !== undefined &&
24644-
(((el as any)[SOURCES_PLAN_MISSES] as number | undefined) ?? 0) < SOURCES_PLAN_MISS_LIMIT
24645-
)
24640+
// dying with a discarded `resolved`. Hosts whose scans keep failing stop
24641+
// paying the attach once SOURCES_PLAN_MISS_LIMIT trips. Copy the miss
24642+
// count onto a replacement record so poison survives the next resolve
24643+
// without becoming a DOM expando.
24644+
const misses =
24645+
prev === undefined
24646+
? 0
24647+
: (((prev as Record<symbol, unknown>)[SOURCES_PLAN_MISSES] as number | undefined) ?? 0);
24648+
if (!formHost && prev !== undefined && misses < SOURCES_PLAN_MISS_LIMIT)
2464624649
attachSourcesPlan(el, out!, sources, winners);
24650+
if (out !== prev && misses !== 0) (out as Record<symbol, unknown>)[SOURCES_PLAN_MISSES] = misses;
2464724651
return out;
2464824652
}
2464924653

‎packages/octane/tests/single-spread-fast-path.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ function watchWrites(el: Element): MutationObserver {
2727
return observer;
2828
}
2929

30+
// Source-plan bookkeeping belongs on the committed prop record. Stamping it on
31+
// the host leaks renderer state after teardown and is the hot-path DOM expando
32+
// the seed/ownership contract forbids.
33+
function hostOwnSourcePlanKeys(el: Element): string[] {
34+
return Object.getOwnPropertySymbols(el)
35+
.map((key) => key.description ?? '')
36+
.filter((description) => description.startsWith('octane.host-prop-sources'));
37+
}
38+
3039
const EDGE = {
3140
cls: 'edge',
3241
d: 'M0 0L1 1',
@@ -173,6 +182,35 @@ describe('a single spread source beside named props', () => {
173182
expect(input.value).toBe('second');
174183
});
175184

185+
it('keeps source-plan bookkeeping off the host across stable and reshaped commits', () => {
186+
const r = mount(FastPathDiv, { tick: 'a', cls: 'row', attrs: { title: 'one' } });
187+
const target = r.find('#fp-div');
188+
189+
// Second commit attaches the plan; the third replays it. Neither may
190+
// write plan state onto the element — the success path used to reset a
191+
// miss counter as a live DOM expando.
192+
r.update(FastPathDiv, { tick: 'b', cls: 'row', attrs: { title: 'one' } });
193+
r.update(FastPathDiv, { tick: 'c', cls: 'row', attrs: { title: 'one' } });
194+
expect(r.find('#div-tick').textContent).toBe('c');
195+
expect(target.getAttribute('title')).toBe('one');
196+
expect(hostOwnSourcePlanKeys(target)).toEqual([]);
197+
198+
// Consecutive shape changes still reach the DOM after the plan gives
199+
// up, and the miss count that implements that give-up stays off the host
200+
// through unmount.
201+
r.update(FastPathDiv, { tick: 'd', cls: 'row', attrs: { title: 'one', 'data-x': '1' } });
202+
r.update(FastPathDiv, { tick: 'e', cls: 'row', attrs: { 'data-y': '2' } });
203+
r.update(FastPathDiv, { tick: 'f', cls: 'row', attrs: { 'data-z': '3' } });
204+
r.update(FastPathDiv, { tick: 'g', cls: 'row', attrs: { title: 'done' } });
205+
expect(target.getAttribute('title')).toBe('done');
206+
expect(target.getAttribute('data-x')).toBeNull();
207+
expect(target.getAttribute('data-y')).toBeNull();
208+
expect(target.getAttribute('data-z')).toBeNull();
209+
expect(hostOwnSourcePlanKeys(target)).toEqual([]);
210+
r.unmount();
211+
expect(hostOwnSourcePlanKeys(target)).toEqual([]);
212+
});
213+
176214
it('evaluates a spread-source getter once per commit and writes its latest value', () => {
177215
let calls = 0;
178216
const attrs = {

0 commit comments

Comments
 (0)