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

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

I maintainer di solito rispondono entro 1 giorno

@semanym ci sta già lavorando.

Dal 29/11/2026.

  • #5273 di @semanym — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, typescript
Ambito
frontend

Direzione di ricerca

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.

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

Descrizione

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

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.