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

Đang mở
#5,117 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@brenelz đang làm issue này rồi.

Từ ngày 24/11/2026.

  • #5193 của @brenelz — đang mở

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Lĩnh vực
frontend, testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
37k
Fork
1.2k
Merge trung bình
8 giờ 43 phút
Pull request đã merge (30 ngày)
365

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của solidjs/solid

Tất cả issue của solidjs/solid

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.