[signals] A row moved into another keyed createOptimisticStore renders empty under Show when a per-row memo reads the store

未关闭
#5,202 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@semanym 已经在做这个了。

开始于 2026年11月29日。

  • #5273 来自 @semanym —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
52/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
frontend

调研方向

Start by running the supplied jsdom reproduction and trace the keyed createOptimisticStore updates alongside the per-row createMemo and nested Show. Compare the failing case with the stated variants that render correctly to isolate the interaction. Done means the moved row renders its text under Show during the outstanding re-asks and the reproduction passes.

由索引模型根据 Issue 内容生成。

描述

On main 30e7805eb (jsdom). Three keyed createOptimisticStore(async, [], { key: "id" }) lists. Each row in For is Show when={r.id < 0} fallback={<>text<Show when={i() < len - 1}>v</Show></>}, where i is a per-row createMemo doing a findIndex over the store.

A reorder in To do and a move of #4 from Doing to Done are both out. The reorder lands, and its action re-asks all three stores. While those re-asks and the first move of #4 are out, a guess moves #4 back into Doing (a copy of the row). Doing's length becomes 2, and the row before it shows its "v" (so it sees a next row), but the moved card's <i> is empty. Neither Show branch renders.

It renders correctly without the To do reorder, without the outer Show, or with the index read straight into the text instead of through the memo. It may be the same family as #5192 (a moved row renders with no text while held writes are out). That repro uses createOptimistic over a signal. This one uses keyed stores, and the row moves between stores.

/**
 * @jsxImportSource @solidjs/web
 * @vitest-environment jsdom
 */
import { test, expect } from "vitest";
import { For, Show, Loading, action, createMemo, createOptimisticStore, flush, refresh } from "solid-js";
import { render } from "../src/index.js";
const tick = async () => { for (let i = 0; i < 4; i++) { await new Promise(r => setTimeout(r, 0)); flush(); } };
type C = { id: number; t: string };

test("a row moved into another keyed optimistic store renders empty under Show when a per-row memo reads the store", async () => {
  const asks: any[] = [];
  const ask = (k: string) => new Promise<any>((res, rej) => asks.push({ k, res, rej }));
  const find = (k: string) => asks.splice(asks.findIndex(a => a.k === k), 1)[0];
  const placed = (rs: C[], c: C, i: number) => { const n = rs.filter(x => x.id !== c.id); n.splice(i, 0, c); return n; };
  const c = document.body.appendChild(document.createElement("div"));
  let api: any;
  function Board() {
    const L: any = {};
    for (const k of ["todo", "doing", "done"]) {
      const [s, set] = (createOptimisticStore as any)(async () => await ask(k), [], { key: "id" });
      L[k] = { s, set };
    }
    const move = action(function* (card: C, from: string, to: string, i: number) {
      if (from !== to) L[from].set((rs: C[]) => rs.filter(x => x.id !== card.id));
      L[to].set((rs: C[]) => placed(rs, card, i));
      yield ask(`move:${card.id}`);
      refresh(L.todo.s); refresh(L.doing.s); refresh(L.done.s);
    });
    api = { L, move };
    const Col = (p: { col: string }) => <Loading fallback="L"><p>{p.col}({L[p.col].s.length}):<For each={L[p.col].s}>{(r: C) => {
      const i = createMemo(() => L[p.col].s.findIndex((x: C) => x.id === r.id));
      return <i><Show when={r.id < 0} fallback={<>[{r.id} {r.t}]<Show when={i() < L[p.col].s.length - 1}>v</Show></>}>adding</Show></i>;
    }}</For></p></Loading>;
    return <><Col col="todo" /><Col col="doing" /><Col col="done" /></>;
  }
  render(() => <Board />, c);
  await tick();
  find("todo").res([{ id: 1, t: "a" }, { id: 2, t: "b" }]); await tick();
  api.move(api.L.todo.s[0], "todo", "todo", 1); await tick();      // reorder in To do
  find("doing").res([{ id: 3, t: "c" }, { id: 4, t: "d" }]); await tick();
  find("done").res([{ id: 5, t: "e" }]); await tick();
  api.move(api.L.doing.s[1], "doing", "done", 1); await tick();    // #4 to Done (its answer never comes)
  find("move:1").res({}); await tick();                             // the reorder lands; re-asks all three (left out)
  expect(c.textContent).toBe("todo(2):[2 b]v[1 a]doing(1):[3 c]done(2):[5 e]v[4 d]");
  api.move({ ...api.L.done.s[1] }, "done", "doing", 1); await tick();   // #4 back to Doing (a copy of the row)
  expect(c.textContent).toBe("todo(2):[2 b]v[1 a]doing(2):[3 c]v[4 d]done(1):[5 e]");
  // actual: "todo(2):[2 b]v[1 a]doing(2):[3 c]vdone(1):[5 e]": #4's row is there but empty
});

Found by an eval app in the ReactiveScript eval (board, a card moved back while the columns re-ask).

主要语言
TypeScript
星标
37k
派生
1.2k
平均合并
8 小时 43 分钟
30 天内合并 PR
365

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

solidjs/solid 的其他 Issue

查看 solidjs/solid 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。