Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/guard-nodeless-store-staging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/signals": patch
---

Prevent an untracked staged-store read beside `latest()` from throwing and halting reactivity when the store has no reactive node.
2 changes: 1 addition & 1 deletion packages/signals/src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2589,7 +2589,7 @@ export function stagedScreen(c: Computed<any>, el?: Signal<any> | Computed<any>)
(el?._config! & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD ||
// #4544: this flush's own write, read by a pass whose posture is only
// inherited, is the frame's derivation, not a probe of it.
(observeFlightHook && holdStagingHook!(c, el!))
(observeFlightHook && el && holdStagingHook!(c, el))
)
return false;
// A transaction only a `latest()` read opened holds nothing: the staging
Expand Down
61 changes: 61 additions & 0 deletions packages/signals/tests/store/nodeless-staged-verdict.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { afterEach, expect, it } from "vitest";
import {
createMemo,
createRenderEffect,
createRoot,
createSignal,
createStore,
flush,
latest,
resetErrorHalt,
untrack
} from "../../src/index.js";

afterEach(() => {
resetErrorHalt();
flush();
});

for (const reader of ["render", "memo"] as const) {
for (const tracked of [false, true]) {
it(`${reader}: latest beside a ${tracked ? "tracked" : "node-less untracked"} store read settles and keeps updating`, async () => {
const requests = [Promise.withResolvers<number>(), Promise.withResolvers<number>()];
let screen: number[] = [];
const app = createRoot(dispose => {
const [step, setStep] = createSignal(0);
const [state, setState] = createStore({ count: 0 });
const data = createMemo(() => {
const current = step();
return current === 0 ? current : requests[current - 1].promise;
});
// An untracked first read leaves the store without a container node.
const read = () => [latest(data), tracked ? state.count : untrack(() => state.count)];
const value = reader === "memo" ? createMemo(read) : read;
createRenderEffect(value, result => {
screen = result;
});
return { dispose, setStep, setState };
});

try {
flush();
expect(screen).toEqual([0, 0]);
for (const current of [1, 2]) {
app.setStep(current);
app.setState(draft => {
draft.count = current;
});
// Before the fix, stagedScreen forwards an absent signal to
// holdStaging and this flush throws while dereferencing its _x.
expect(() => flush()).not.toThrow();
requests[current - 1].resolve(current);
await requests[current - 1].promise;
flush();
expect(screen).toEqual([current, current]);
}
} finally {
app.dispose();
}
});
}
}
Loading