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

Ouverte
#5,202 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@semanym y travaille déjà.

Depuis le 29/11/2026.

  • #5273 par @semanym — ouverte

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
52/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
javascript, typescript
Domaine
frontend

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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

Langage dominant
TypeScript
Étoiles
37k
Forks
1.2k
Merge moyen
8 h 43 min
PR mergées (30 j)
365

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de solidjs/solid

Toutes les issues de solidjs/solid

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.