Skip to content
Merged
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/shallow-immutable-update-4686.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/signals": patch
---

`IMMUTABLE_UPDATE_IN_STORE` no longer reports wholesale replacements on a shallow store, or of a `markRaw` / unwrappable leaf (#4686). Those values are invalidated as a unit, so leaf draft assignment does not narrow who re-runs — the diagnostic's advice does not apply.
7 changes: 7 additions & 0 deletions packages/signals/src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,10 @@ function reportReplacedContainers(
pb: Record<PropertyKey, any>,
writtenKeys: Iterable<PropertyKey> | null
): void {
// Shallow stores (and raw / unwrappable leaves) invalidate the whole
// replaced value as one unit — leaf draft assignment does not narrow
// who re-runs (#4686). The spread-copy diagnostic only helps deep stores.
if (t.s) return;
const keys = writtenKeys ?? Reflect.ownKeys(pb);
const isArray = Array.isArray(pb);
const owner = storeRootOwner(t);
Expand All @@ -1091,6 +1095,9 @@ function reportReplacedContainers(
targetsEqual(ov, nv)
)
continue;
// A raw / unwrappable previous value is itself a leaf: replacing it is
// the write, not a container copy the store could have mutated in place.
if (isRawValue(ov) || !isWrappable(ov)) continue;
if (isArray) {
if (oldArrayItems === null) {
oldArrayItems = new Set<unknown>();
Expand Down
23 changes: 22 additions & 1 deletion packages/signals/tests/attribution-immutable-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { afterEach, describe, expect, it, vi } from "vitest";
import { attribution } from "../src/attribution.js";
import { createStore, flush, reconcile, OBSERVE } from "../src/index.js";
import { createStore, flush, markRaw, reconcile, OBSERVE } from "../src/index.js";
import type { DiagnosticEvent } from "../src/core/dev.js";

afterEach(() => {
Expand Down Expand Up @@ -174,4 +174,25 @@ describe("IMMUTABLE_UPDATE_IN_STORE", () => {
expect(hits).toHaveLength(1);
expect(hits[0].data!.path).toBe("store.a.b");
});

it("does not report replacing a value in a shallow store (#4686)", () => {
const hits = arm();
const [, setStore] = createStore([{ a: 1, b: 2, c: 3 }], { shallow: true });
setStore(s => {
s[0] = { a: 1, b: 2, c: 4 };
});
flush();
expect(hits).toEqual([]);
});

it("does not report replacing a markRaw leaf (#4686)", () => {
const hits = arm();
const leaf = markRaw({ a: 1, b: 2, c: 3 });
const [, setStore] = createStore({ item: leaf });
setStore(s => {
s.item = { a: 1, b: 2, c: 4 };
});
flush();
expect(hits).toEqual([]);
});
});