A store created from a function (writable projection / createProjection), a write to a node is SILENTLY DISCARDED if a descendant of that node was written earlier in the same flush. A plain createStore(value) is correct.
The LLM proposed fix did seem to solve the issue when applied to the @solidjs/signals/../dev.js file. I've provided screenshot of this proposed fix in case it might help you to see/find the problem too.
import { createStore, createRoot, flush, snapshot, untrack, deep } from "@solidjs/signals";
const seed = () => [{ id: 1, selected: true, children: [{ id: 11, selected: true }] }];
function scenario(makeStore, order) {
return createRoot(() => {
const [store, setStore] = makeStore();
untrack(() => deep(store)); // materialize the projection
setStore(prev => {
const row = prev[0];
if (order === "descendant-first") {
row.children[0].selected = false; // descendant
row.selected = false; // ancestor <-- discarded
} else {
row.selected = false; // ancestor
row.children[0].selected = false; // descendant
}
});
flush();
return JSON.stringify(snapshot(untrack(() => deep(store))));
});
}
const plain = () => createStore(seed());
const projection = () => createStore(() => seed(), []);
const EXPECTED = `[{"id":1,"selected":false,"children":[{"id":11,"selected":false}]}]`;
for (const [name, make] of [["plain ", plain], ["projection", projection]])
for (const order of ["ancestor-first", "descendant-first"]) {
const got = scenario(make, order);
console.log(`${got === EXPECTED ? "PASS" : "FAIL"} ${name} ${order.padEnd(17)} ${got}`);
}
Describe the bug
A store created from a function (writable projection / createProjection), a write to a node is SILENTLY DISCARDED if a descendant of that node was written earlier in the same flush. A plain createStore(value) is correct.
The LLM proposed fix did seem to solve the issue when applied to the @solidjs/signals/../dev.js file. I've provided screenshot of this proposed fix in case it might help you to see/find the problem too.
Your Example Website or App
no
Steps to Reproduce the Bug or Issue
(AI generated reproduction):
Expected behavior
See reproduce
Screenshots or Videos
No response
Platform
Windows
Additional context
No response