Skip to content

Commit

Permalink
fix #2065 forward initial value to on
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansolid committed Feb 14, 2024
1 parent 19ab9e5 commit 8de75a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/bright-maps-sing.md
@@ -0,0 +1,5 @@
---
"solid-js": patch
---

fix #2065 forward initial value to `on`
2 changes: 1 addition & 1 deletion packages/solid/src/reactive/signal.ts
Expand Up @@ -953,7 +953,7 @@ export function on<S, Next extends Prev, Prev = Next>(
} else input = deps();
if (defer) {
defer = false;
return undefined;
return prevValue;
}
const result = untrack(() => fn(input, prevInput, prevValue));
prevInput = input;
Expand Down
11 changes: 11 additions & 0 deletions packages/solid/test/signals.spec.ts
Expand Up @@ -81,6 +81,17 @@ describe("Create signals", () => {
set("minds");
expect(temp!).toBe("impure minds");
});
test("Create a Effect with explicit deps, lazy evaluation, and initial value", () => {
let temp: string;
const [sign, set] = createSignal("thoughts");
createRoot(() => {
const fn = on(sign, (v, _, p) => (temp = `impure ${p} ${v}`), { defer: true });
createEffect(fn, "numbers");
});
expect(temp!).toBeUndefined();
set("minds");
expect(temp!).toBe("impure numbers minds");
});
});

describe("Update signals", () => {
Expand Down

0 comments on commit 8de75a4

Please sign in to comment.