Skip to content

Commit e6c85cb

Browse files
authored
Merge pull request #94 from solidjs-community/fix/comp-on-handler
Fixes regression where functions could not be passed inline to component event handlers
2 parents 0e037ef + d1afb7d commit e6c85cb

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

docs/reactivity.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,18 @@ function Component() {
620620
return <div on:click={() => console.log(signal())} />;
621621
}
622622

623+
function Component(props) {
624+
return <div onClick={(e) => props.onClick(e)} />;
625+
}
626+
623627
const Parent = (props) => {
624628
return <Child onClick={props.onClick} />;
625629
};
626630

631+
const Parent = (props) => {
632+
return <Child onClick={(e) => props.onClick(e)} />;
633+
};
634+
627635
const Component = (props) => {
628636
const [signal] = createSignal();
629637
return (
@@ -742,6 +750,9 @@ function Component(props) {
742750
);
743751
}
744752

753+
const [signal, setSignal] = createSignal();
754+
let el = <Child foo={() => signal()}></Child>;
755+
745756
function Component(props) {
746757
const value = props.staticValue;
747758
}

src/rules/reactivity.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,16 +568,14 @@ export default createRule({
568568
}
569569

570570
// If there are any unnamed derived signals, they must match a tracked
571-
// scope exactly. Usually anonymous arrow function args to createEffect,
571+
// scope. Usually anonymous arrow function args to createEffect,
572572
// createMemo, etc.
573573
const { unnamedDerivedSignals } = currentScope();
574574
if (unnamedDerivedSignals) {
575575
for (const node of unnamedDerivedSignals) {
576576
if (
577-
!currentScope().trackedScopes.find(
578-
(trackedScope) =>
579-
trackedScope.node === node &&
580-
(trackedScope.expect === "function" || trackedScope.expect === "called-function")
577+
!currentScope().trackedScopes.find((trackedScope) =>
578+
matchTrackedScope(trackedScope, node)
581579
)
582580
) {
583581
context.report({

test/rules/reactivity.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,16 @@ export const cases = run("reactivity", rule, {
177177
const [signal, setSignal] = createSignal(1);
178178
return <div on:click={() => console.log(signal())} />;
179179
}`,
180+
`function Component(props) {
181+
return <div onClick={e => props.onClick(e)} />;
182+
}`,
180183
// event listeners are reactive on components
181184
`const Parent = props => {
182185
return <Child onClick={props.onClick} />;
183186
}`,
187+
`const Parent = props => {
188+
return <Child onClick={e => props.onClick(e)} />;
189+
}`,
184190
// Pass reactive variables as-is into provider value prop
185191
`const Component = props => {
186192
const [signal] = createSignal();
@@ -289,6 +295,9 @@ export const cases = run("reactivity", rule, {
289295
}}</div>
290296
);
291297
}`,
298+
// passing function instead of signal
299+
`const [signal, setSignal] = createSignal();
300+
let el = <Child foo={() => signal()}></Child>`,
292301
// static* prefix for props
293302
`function Component(props) {
294303
const value = props.staticValue;

0 commit comments

Comments
 (0)