[2.0 / main] Store lane derivations staged per key: 8 undefined, torn or stuck row repros share one branch

Aperta
#5,117 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@brenelz ci sta già lavorando.

Dal 24/11/2026.

  • #5193 di @brenelz — aperta

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript, react, typescript
Ambito
frontend, testing

Direzione di ricerca

Start by reading packages/signals/src/store/store.ts at holdWithDerive (lines 1998–2010) and the pinned tests listed in the issue; the issue names packages/web/test/store-lane-staging.spec.tsx for repros W and L6. First establish the intended rule for staging a store target's lane derivation, since the issue describes this as an unresolved design question. Done means the eight repros pass while the listed regression tests remain passing.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

On main at 99db9bce4, one branch in holdWithDerive (store.ts#L1998-L2010) is behind 8 fuzz repros of undefined, duplicate, torn and stuck store rows under actions. When a pass is lane work, this branch stages a store property's write in the lane, one key at a time. Disabling the branch fixes all 8 and fails 16 pinned tests. A probe that removes it is not a fix, but it shows the 8 share one mechanism, and that settling it needs a ruling: should a store target's lane derivation be staged as one unit or per key?

What goes wrong. When a projection or derived store re-derives as lane work, each key it writes is listed on the lane and marked CONFIG_OVERRIDE on its own. Keys the lane pass does not reach keep the committed value. The same target can then hold lane values and committed values side by side, so readers see a mix that no single answer produced. The rows below are that mix, seen from different readers.

Symptoms (each repro exits 1 on main and 0 with the branch disabled)

repro what the screen shows
W One projection field shows two values in one frame: [p=G] [p=o:0]. The reader outside a <Show> that the held write is closing sees the guess; the reader inside sees the old answer. A createMemo in place of the projection shows [p=G] [p=G].
L6 <For> over a keyed createProjection of a filtered createOptimisticStore runs a row whose item is undefined (Cannot read properties of undefined (reading 'id')), and reactivity halts. Steps: toggle a row out of the filter (guess), delete it in another action and refresh, then the list lands without it.
R5, R11 Board shape: two keyed optimistic stores, rows moved between them, and a keyed projection over one. The projection's mapArray runs an undefined row when an answer lands (R5 after a rejected move, R11 after a path guess on a moved row).
R8 Same board shape. An event handler's untracked todo.some(r => r.id === 3) throws after a reverse, a rename and a toggle.
R4L-2 A row moved out and back, where the second move writes the answer signals instead of calling refresh(). Both stores stay isPending() === true forever, and a later delete is lost.
R4L-6 Three stores with rows lent between them. One store never shows its own landed row, and two stay isPending() after a final refresh.
R4L-9 createStore(fn) over a keyed optimistic store reads 3d'2,3d'2 (row 3 twice, row 4 gone) until the last re-ask lands.

W and L6 are web specs with compiled JSX (below). The other six use only solid-js primitives (createOptimisticStore, createProjection, createStore(fn), mapArray, action, refresh), with no renderer. I can attach them if useful.

Probe: false && in front of the laneStageHook && lane !== null && ... condition. All 8 repros flip to passing. packages/signals goes from 7242 passed to 16 failed and 7226 passed:

  • derived-store-lane-derive.test.ts: store: a derive over latest() shows the action's value now
  • projection-lane-length-4631.test.ts (#4631): both "declined first" cases
  • projection-second-guess-4629.test.ts (#4629): the three "through a keyed projection" cases
  • show-stale-child-in-action-4137.test.ts (#4137): a derived record drops the action's row while the list keeps it
  • store/derived-store-heal-4451.test.ts (#4451): three cases
  • switch-under-guess-holds.test.ts: "fetch read first, through a projection", in all four build modes
  • unread-derive-midflight-mount-4491.test.ts (#4491): storeJSON and storeKeys as the memo form

Those tests pin the reason the branch exists. A display-ahead read of a projection is lane work, and its value should be the lane's derivation, as a memo's would be (D-25). The 8 repros are what happens when only some keys of the target take that path.

Question: should a lane derivation of a store target be staged and committed as one unit, so all of its keys come from one pass? Or is per-key staging intended, with the readers (mapArray, For, some, createStore(fn)) expected to cope with a mixed target? Either answer would let the 8 be fixed against a rule.

spec (W and L6), as packages/web/test/store-lane-staging.spec.tsx
/**
 * @jsxImportSource @solidjs/web
 * @vitest-environment jsdom
 */
import { expect, test } from "vitest";
import {
  For,
  Loading,
  Show,
  action,
  createDeferred,
  createMemo,
  createOptimistic,
  createOptimisticStore,
  createProjection,
  createSignal,
  flush,
  latest,
  refresh,
  untrack
} from "solid-js";
import { render } from "../src/index.js";

process.on("unhandledRejection", () => {});

const tick = async () => {
  for (let i = 0; i < 4; i++) {
    await new Promise(r => setTimeout(r, 0));
    flush();
  }
};

function desk() {
  const asks: { key: string; res: (v: any) => void }[] = [];
  const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
  const land = async (key: string, v: any = key) => {
    const i = asks.findIndex(a => a.key === key);
    if (i < 0) throw new Error(`no ask ${key}; open: ${asks.map(a => a.key)}`);
    asks.splice(i, 1)[0].res(v);
    await tick();
  };
  const drain = async () => {
    for (let n = 0; n < 30 && asks.length; n++) {
      for (const a of asks.splice(0)) a.res(a.key);
      await tick();
    }
  };
  return { ask, land, drain, open: () => asks.map(a => a.key).join(",") };
}

function mount(view: () => any) {
  const container = document.body.appendChild(document.createElement("div"));
  const dispose = render(view, container);
  return {
    frame: () => container.textContent!.replace(/\s+/g, " ").trim(),
    dispose: () => (dispose(), container.remove())
  };
}

test("W: one projection field shows one value in a frame, inside and outside a closing <Show>", async () => {
  const d = desk();
  let act!: (x: number) => void;
  const app = mount(() => {
    const [s, setS] = createSignal(0);
    const [o, setO] = createOptimistic(() => d.ask("o:" + s()));
    const p = createProjection<{ n: any }>(draft => void (draft.n = o()), { n: 0 });
    act = action(function* (x: number) {
      setS(x);
      setO("G");
      yield d.ask("save");
    });
    return (
      <div>
        [p={p.n}]{" "}
        <Show when={s() < 2}>
          <span>[p={p.n}]</span>
        </Show>
      </div>
    );
  });
  flush();
  await tick();
  await d.drain();
  act(2);
  flush();
  await tick();
  const mid = app.frame();
  await d.drain();
  app.dispose();
  expect(new Set([...mid.matchAll(/\[p=([^\]]*)\]/g)].map(m => m[1])).size, mid).toBe(1);
});

test("L6: <For> over a keyed projection of an optimistic list does not read an undefined row", async () => {
  const d = desk();
  const errors: string[] = [];
  const origError = console.error;
  console.error = (...a: any[]) => void errors.push(String(a[0]) + " " + String(a[1]?.message ?? ""));
  let tog!: (i: number, v: boolean) => void, del!: (id: number) => void;
  const app = mount(() => {
    const [rows, setRows] = createOptimisticStore<{ id: number; t: string; d: boolean }[]>(
      () => d.ask("list"),
      [],
      { key: "id" }
    );
    const openList = createMemo(() => rows.filter(x => !x.d));
    const open = createProjection(() => openList(), [], { key: "id" });
    tog = action(function* (i: number, v: boolean) {
      setRows(dr => void (dr[i].d = v));
      yield d.ask("tog");
    });
    del = action(function* () {
      yield d.ask("del");
      refresh(rows);
    });
    return (
      <Loading fallback="loading">
        <p>
          open:<For each={open}>{y => <i>&lt;{y.id}{y.t}&gt;</i>}</For>
        </p>
      </Loading>
    );
  });
  flush();
  await tick();
  await d.land("list", [{ id: 1, t: "c", d: false }]);
  tog(0, true);
  await tick();
  del(1);
  await tick();
  await d.land("del", 0);
  const got = app.frame();
  await d.land("list", []);
  await d.land("tog", 0);
  const end = app.frame();
  app.dispose();
  console.error = origError;
  expect({ got, end, errors }).toEqual({ got: expect.not.stringContaining("undefined"), end: "open:", errors: [] });
});

How it was found: differential fuzzing of Solid against the ReactiveScript spec interpreter. The 8 repros came from separate rounds and were grouped by probing each candidate branch against every open repro and the signals suite.

Lingua principale
TypeScript
Stelle
37k
Fork
1.2k
Merge medio
8h 43m
PR unite (30g)
365

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di solidjs/solid

Tutte le issue di solidjs/solid

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.