Skip to content

Commit

Permalink
Merge pull request #123 from solidjs-community/fix/multiple-sync-props
Browse files Browse the repository at this point in the history
Only mark props as reactive for non-sync callbacks, fixes #110.
  • Loading branch information
joshwilsonvu authored Dec 30, 2023
2 parents 16a5209 + 31fbc88 commit 4282b29
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,12 @@ function Component(props) {
return <div use:someHook={() => props.count} />;
}

function formObjectDispatch(formObject, action) {
const { field } = action.payload;
formObject.findIndex((props) => props.field === field);
formObject.findIndex((props) => props.field === field);
}

```
<!-- AUTO-GENERATED-CONTENT:END -->
Expand Down
2 changes: 1 addition & 1 deletion src/rules/reactivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ export default createRule<Options, MessageIds>({
/** Populates the function stack. */
const onFunctionEnter = (node: ProgramOrFunctionNode) => {
if (isFunctionNode(node)) {
markPropsOnCondition(node, (props) => isPropsByName(props.name));
if (scopeStack.syncCallbacks.has(node)) {
// Ignore sync callbacks like Array#forEach and certain Solid primitives
return;
}
markPropsOnCondition(node, (props) => isPropsByName(props.name));
}
scopeStack.push(new ScopeStackItem(node));
};
Expand Down
6 changes: 6 additions & 0 deletions test/rules/reactivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ export const cases = run("reactivity", rule, {
function Component(props) {
return <div use:someHook={() => props.count} />;
}`,
// f*cking insane edge case with multiple functions taking props as sync callbacks (#110)
`function formObjectDispatch(formObject, action) {
const { field } = action.payload;
formObject.findIndex((props) => props.field === field);
formObject.findIndex((props) => props.field === field);
}`,
],
invalid: [
// Untracked signals
Expand Down

0 comments on commit 4282b29

Please sign in to comment.