For index accessors stay stale after an optimistic reorder when the mutation is a router action
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 50/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
- 領域
- frontend
調査の方向性
Run the provided TypeScript reproduction and compare the router action path with the plain async and nested Solid action variants. Trace the interaction among the router action/query, createOptimisticStore, and For index accessors; the fix is done when the settled list reads b:0 a:1 c:2 and the optimistic overlay is removed after the action.
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
When a Solid action reorders rows in an optimistic store optimistically and then calls a router action, the rows move but For's index accessors do not, and they never update afterwards. After the router action finishes and the query behind the store refetches, the list shows the new order with the old indexes (b:1 a:0 c:2) until the page is reloaded. Any code that uses i() then targets the wrong row. In a kanban board this disabled the "move up" button on the wrong card and computed wrong drop positions.
Every piece of the repro is needed. The same reorder recovers correctly (indexes are stale only during the transition, then correct) when:
- the mutation is a plain async function followed by
revalidate(getCards.key)instead of a routeraction, - the mutation is a nested Solid
actionthat callsrevalidate(getCards.key), - the optimistic store derives from a plain
createMemo(async …)instead of a routerquery.
Without the optimistic write (just the router action, then the list re-renders from the refetched query), the indexes are also correct.
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 };
let 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");
const swapOnServer = routerAction(async () => {
await wait(150);
const [x, y] = [...db].sort((p, q) => p.order - q.order);
db = db.map(c => (c.id === x.id ? { ...c, order: y.order } : c.id === y.id ? { ...c, order: x.order } : c));
}, "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(swapOnServer);
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>
<ul>
<For each={sorted()}>{(r, i) => <li>{r.id}:{i()}</li>}</For>
</ul>
</>
);
}
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. The list reads
a:0 b:1 c:2. - Click
swap. The list immediately readsb:1 a:0 c:2. - Wait. It still reads
b:1 a:0 c:2indefinitely.
The same happens when the router action is a "use server" function returning reload({ revalidate: [getCards.key] }), returning nothing, or returning a value, and with singleFlight: false. It also happens in the production build, and on 2.0.0-next.28.
Expected behavior
b:0 a:1 c:2 once the action settles, as with the plain-async and nested-Solid-action variants above.
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 stale value is For's index accessor (solid-js), but only the router action path leaves it stuck: a nested Solid action doing the same mutation and revalidate recovers. A related symptom in the same setup: if the router action resolves without changing the data (for example it returns new Error("rejected"), the documented validation pattern), the optimistic store overlay itself is never dropped and keeps showing the rejected reorder. That may share a cause; I can file it separately.
- 主要言語
- TypeScript
- スター
- 1.3k
- フォーク
- 180
- 平均マージ
- 1日 6時間
- マージ済み PR(30日)
- 20
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
solidjs/solid-router のほかの issue
-
難易度 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 1週間以上 初心者へのやさしさ 35/100
solidjs/solid-router#569 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 38/100
solidjs/solid-router#518 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
solidjs/solid-router#502 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
solidjs/solid-router の issue をすべて見る
似ている issue
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
StabilityNexus/Fate-EVM-Frontend#153 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
code-yeongyu/oh-my-openagent#9039 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Tencent/teamai-cli#862 ·
メンテナーはふだん 1 日以内に返信
-
bug good first issue hacktoberfest redis
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
libredb/libredb-studio#1164 ·
メンテナーはふだん 1 日以内に返信
-
flake
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信