Skip to content

Commit 31fbc88

Browse files
committed
Only mark props as reactive for non-sync callbacks, fixes #110.
1 parent 16a5209 commit 31fbc88

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docs/reactivity.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,12 @@ function Component(props) {
816816
return <div use:someHook={() => props.count} />;
817817
}
818818

819+
function formObjectDispatch(formObject, action) {
820+
const { field } = action.payload;
821+
formObject.findIndex((props) => props.field === field);
822+
formObject.findIndex((props) => props.field === field);
823+
}
824+
819825
```
820826
<!-- AUTO-GENERATED-CONTENT:END -->
821827

src/rules/reactivity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,11 @@ export default createRule<Options, MessageIds>({
315315
/** Populates the function stack. */
316316
const onFunctionEnter = (node: ProgramOrFunctionNode) => {
317317
if (isFunctionNode(node)) {
318-
markPropsOnCondition(node, (props) => isPropsByName(props.name));
319318
if (scopeStack.syncCallbacks.has(node)) {
320319
// Ignore sync callbacks like Array#forEach and certain Solid primitives
321320
return;
322321
}
322+
markPropsOnCondition(node, (props) => isPropsByName(props.name));
323323
}
324324
scopeStack.push(new ScopeStackItem(node));
325325
};

test/rules/reactivity.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ export const cases = run("reactivity", rule, {
328328
function Component(props) {
329329
return <div use:someHook={() => props.count} />;
330330
}`,
331+
// f*cking insane edge case with multiple functions taking props as sync callbacks (#110)
332+
`function formObjectDispatch(formObject, action) {
333+
const { field } = action.payload;
334+
formObject.findIndex((props) => props.field === field);
335+
formObject.findIndex((props) => props.field === field);
336+
}`,
331337
],
332338
invalid: [
333339
// Untracked signals

0 commit comments

Comments
 (0)