Optimistic store write is never reverted when a router action resolves without changing the data
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- typescript
- 领域
- frontend
调研方向
Reproduce the issue with the provided Cards example, focusing on createOptimisticStore, the router query, useAction, and the router action's settlement path. Compare the listed throwing, returning, plain async, and nested Solid action variants to identify where the optimistic overlay is left in place. Done means a settled router action restores a0 b1 c2 when the underlying data is unchanged, with the regression covered by a test.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
When a Solid action makes an optimistic write to a store and then calls a router action that resolves without changing the underlying data, the optimistic write is never reverted. The store keeps showing the tentative value indefinitely, even after the query it derives from has refetched the unchanged data; only a page reload shows the truth.
This hits the router's documented validation pattern directly: an action that rejects the mutation by returning new Error("…") leaves the UI showing the change it just rejected. In a kanban board, moving a locked card showed the "is locked" error while the card stayed in its new column.
It happens whatever the router action resolves with (an Error, a plain value, or nothing). It does not happen when:
- the router action throws (the overlay reverts),
- the mutation is a plain async function followed by
revalidate(getCards.key), - the mutation is a nested Solid
actionthat callsrevalidate(getCards.key).
This looks related to #619 (same setup: optimistic store, router query, router action), where the store's value lands but For's index accessors stay stale.
Your Example Website or App
The component below. It needs no server functions: the query and the router action are both client-side.
Steps to Reproduce the Bug or Issue
With @solidjs/[email protected], solid-js/@solidjs/web 2.0.0-rc.9 and @solidjs/[email protected] (client start mode):
import { action as routerAction, createRouter, query, useAction } from "@solidjs/router";
import { action, createMemo, createOptimisticStore, For, Loading } from "solid-js";
type Card = { id: string; order: number };
const db: Card[] = [{ id: "a", order: 0 }, { id: "b", order: 1 }, { id: "c", order: 2 }];
const wait = (ms: number) => new Promise(r => setTimeout(r, ms));
const getCards = query(async () => {
await wait(20);
return db.map(c => ({ ...c }));
}, "cards");
// Rejects the change without touching `db`.
const rejectSwap = routerAction(async () => {
await wait(150);
return new Error("rejected");
}, "reject-swap");
function Cards() {
const data = createMemo(() => getCards());
const [cards, setCards] = createOptimisticStore(() => data(), [] as Card[]);
const sorted = () => [...cards].sort((x, y) => x.order - y.order);
const call = useAction(rejectSwap);
const swap = action(function* () {
setCards(list => {
const [x, y] = [...list].sort((p, q) => p.order - q.order);
const t = x.order;
x.order = y.order;
y.order = t;
});
yield call();
});
return (
<>
<button onClick={() => swap()}>swap</button>
<pre>{sorted().map(c => `${c.id}${c.order}`).join(" ")}</pre>
</>
);
}
const Router = createRouter({ routes: [{ path: "/", component: Cards }] });
export default function App() {
return <Router>{props => <Loading fallback={<p>…</p>}>{props.children}</Loading>}</Router>;
}
- Load the page. It reads
a0 b1 c2. - Click
swap. It immediately readsb0 a1 c2(the optimistic write). - Wait. It still reads
b0 a1 c2indefinitely. Reloading showsa0 b1 c2.
Replacing return new Error("rejected") with return "ok" or with no return gives the same result. Rethrowing the returned error from the generator makes no difference. With a "use server" router action the behavior is the same, in dev and in the production build, and on 2.0.0-next.28.
Expected behavior
The optimistic write reverts when the action settles, leaving a0 b1 c2, as it does when the router action throws or when the mutation is a plain async function or a nested Solid action.
Screenshots or Videos
No response
Platform
- OS: macOS 15 (arm64)
- Browser: Chromium 151 (Playwright headless shell)
- Node: 24.21.0
- Versions:
@solidjs/router2.0.0-next.30 (also 2.0.0-next.28),solid-js/@solidjs/web/@solidjs/signals2.0.0-rc.9,@solidjs/vite-plugin3.0.0-next.44, Vite 8.3.0
Additional context
I have not traced the root cause. The three control variants above use the same query, the same derived createOptimisticStore, and the same unchanged data, so the router action's settle path is the ingredient that leaves the overlay in place.
- 主要语言
- TypeScript
- 星标
- 1.3k
- 派生
- 180
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 27
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
solidjs/solid-router 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 50/100
solidjs/solid-router#625 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 74/100
solidjs/solid-router#624 ·
维护者通常 1 天内回复
-
<A> costs ~6us of server CPU per instance during SSR (20x a plain <a>), mostly mergeProps/splitProps未关闭
难度 4/5 3-5 天 新手友好度 55/100
solidjs/solid-router#583 ·
维护者通常 1 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
solidjs/solid-router#569 · 3 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 3/5 1-2 天 新手友好度 38/100
solidjs/solid-router#518 · 2 条评论 ·
维护者通常 1 天内回复
查看 solidjs/solid-router 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
openedx/frontend-app-authoring#3274 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
-
area/documentation status/need-triage
难度 1/5 1 小时以内 新手友好度 95/100
google-gemini/gemini-cli#29548 ·
维护者通常 1 天内回复
-
sdk-typescript vector-store
难度 2/5 半天 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复