[signals] A guessed row remounts when the truth lands from a local source store, even with the same id

Open
#5,136 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@flipcyde101 is already working on this.

Since Nov 21, 2026.

  • #5144 by @flipcyde101 — open

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
frontend

Research direction

The issue provides a TypeScript reproduction using createOptimisticStore, createStore, and mapArray, but names no source or test file. Start by locating the optimistic store implementation and its tests, then reproduce the local source store case and compare it with the fetch plus refresh() case. Done means the same-id row mounts once and updates pending in place for both forms, while different ids still remount.

Written by the indexing model from the issue text.

Description

Summary

An action adds a row optimistically, then writes the saved row into the source of truth. The guess reverts and the saved row shows in the same frame, with no blink. But when the optimistic store is derived from a local store (createOptimisticStore(() => source, [])), the keyed list remounts the row, even when the saved row has the same id as the guess.

When the truth comes from a fetch instead (createOptimisticStore(async () => fetchTodos(), []) plus refresh() in the action), the same steps keep the row. It mounts once and updates in place. Only the local-source form drops it.

Found on main @ 8bfca0d while answering #5129.

Repro
const [source, setSource] = createStore<Todo[]>([]);
const [todos, setTodos] = createOptimisticStore<Todo[]>(() => source, []);

createRoot(() => {
  const rows = mapArray(() => todos, row => {
    console.log("mount", row.id);
    createRenderEffect(() => `${row.id}:${!!row.pending}`, v => console.log("row", v));
    return row;
  });
  createRenderEffect(() => rows().length, () => {});
});

let resolveSave!: (t: Todo) => void;
const add = action(function* (text: string) {
  setTodos(t => { t.push({ id: "tmp-1", text, pending: true }); }); // guess
  const saved: Todo = yield new Promise<Todo>(r => (resolveSave = r));
  setSource(s => { s.push(saved); }); // truth
});

add("milk");
// flush, then:
resolveSave({ id: "tmp-1", text: "milk" }); // the server kept the client's id
Observed
Truth Same id Different id
Local source store, setSource in the action mount tmp-1, then mount tmp-1 again remounts
Fetch plus refresh() in the action one mount tmp-1; the row flips pending true → false in place remounts

Every case ends on the right value.

Expected

With the same id, the guess row carries over to the saved row in both forms, as it does in the fetch form. The local form looks like it adopts source's own row proxies instead of reconciling them by key, so the guessed row is dropped and a new one is mounted.

Dominant language
TypeScript
Stars
37k
Forks
1.2k
Avg merge
8h 43m
Merged PRs (30d)
365

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from solidjs/solid

All issues in solidjs/solid

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.