Skip to content

Commit bbb1fe8

Browse files
committed
fix(compiler): stop seedRenderReads from over-nominating non-binding identifiers
The render-read scan in collectUseArgumentRoots had two over-nomination issues that caused handler-only calculations and property-name collisions to be wrongly wrapped in useMemo: 1. Non-computed MemberExpression properties (e.g. `length` in `visible.length`) and non-computed Property keys were treated as binding references. Add explicit handlers that walk only the binding-relevant children, matching collectFreeIdentifiers. 2. Nested function bodies (event handlers like `onClick={() => fn(x)}`) were walked with inRenderTree=true, seeding identifiers that are only accessed when the event fires. Reset inRenderTree to false when entering function bodies; the existing nextInRenderTree logic re-enters render-tree mode at any JSX boundary inside.
1 parent fe0f933 commit bbb1fe8

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎packages/octane/src/compiler/compile.js‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10774,7 +10774,12 @@ function collectUseArgumentRoots(
1077410774
const inner = new Set(bound);
1077510775
for (const param of n.params || []) collectPatternNames(param, inner);
1077610776
collectScopeDeclaredNames(n.body, inner);
10777-
walk(n.body, inner, inRenderTree);
10777+
// A nested function body is not a render read: event handlers and
10778+
// callbacks execute lazily, not during rendering. Reset inRenderTree
10779+
// so identifiers inside are not seeded. If the body contains JSX
10780+
// (e.g. a .map() callback returning elements), nextInRenderTree
10781+
// re-enters render-tree mode at the JSX boundary.
10782+
walk(n.body, inner, false);
1077810783
return;
1077910784
}
1078010785
if (LOOP_TYPES.has(n.type)) {
@@ -10811,6 +10816,18 @@ function collectUseArgumentRoots(
1081110816
walk(n.empty, bound, true);
1081210817
return;
1081310818
}
10819+
// Non-computed member access — `obj.prop`: the property is a static
10820+
// name, not a binding reference. Only the object is a render read.
10821+
if (seedRenderReads && n.type === 'MemberExpression' && !n.computed) {
10822+
walk(n.object, bound, inRenderTree);
10823+
return;
10824+
}
10825+
// Non-computed object-literal key — `{ key: value }`: the key is a
10826+
// static name. Only the value carries binding references.
10827+
if (seedRenderReads && n.type === 'Property' && !n.computed) {
10828+
walk(n.value, bound, inRenderTree);
10829+
return;
10830+
}
1081410831
if (seedRenderReads && inRenderTree && n.type === 'Identifier' && !bound.has(n.name)) {
1081510832
into.add(n.name);
1081610833
}

0 commit comments

Comments
 (0)