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

オープン
#5,117 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@brenelz がすでに取り組んでいます。

2026年11月24日 から。

  • #5193 @brenelz による — オープン

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript, react, typescript
領域
frontend, testing

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
37k
フォーク
1.2k
平均マージ
8時間 43分
マージ済み PR(30日)
365

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

solidjs/solid のほかの issue

solidjs/solid の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。