Skip to content

Bug in solid 2.rc6 store #3271

Description

@Azravos

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):

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}`);
  }

Expected behavior

See reproduce

Screenshots or Videos

Image

No response

Platform

Windows

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions