Navigation commit failure leaves the loading state active and causes inconsistent internal state
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 48/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- react, typescript
研究方向
Read packages/react/src/runtime/pages-client.ts around finishNavigation() and packages/void/src/pages/navigation-engine.ts around makeCommit(). Trace how pending visits, reducer failure actions, internal committed state, and scrollRestoration.writeHistory() interact when history writing throws. Reproduce with the provided component and verify the error propagates, navigation returns to idle, state stays consistent, and an older failure cannot reset a newer navigation.
由索引模型根據 Issue 內容生成。
描述
Problem
When history.pushState() or history.replaceState() throws during navigation, router.visit() rejects, but useNavigation().state remains loading.
Additionally, Void updates its internal committed state before writing browser history. If the history update fails, the browser URL and internal navigation state become inconsistent.
Reproduction
- Configure a valid Void page at
/b. - Render the following React component:
import { useNavigation, useRouter } from '@void/react';
export default function Example() {
const router = useRouter();
const navigation = useNavigation();
async function navigate() {
const original = history.pushState;
history.pushState = () => {
throw new DOMException(
'History update failed',
'SecurityError',
);
};
try {
await router.visit('/b');
} catch {
// Inspect the navigation state after failure.
} finally {
history.pushState = original;
}
}
return (
<>
<p>Navigation: {navigation.state}</p>
<button onClick={navigate}>Navigate</button>
</>
);
}
- Click the button and inspect the navigation state and browser URL after the failed navigation.
Actual behavior
router.visit()rejects.useNavigation().stateremainsloading.- The browser URL remains unchanged.
- Void's internal current URL and committed resource have already been updated.
- Restoring normal history behavior and navigating to another page clears the stuck navigation state.
Expected behavior
A failed history update should terminate the navigation cleanly and preserve state consistency.
- The navigation state returns to
idle. - The original error propagates to the
router.visit()caller. - The browser URL, rendered page, and internal navigation state remain consistent.
- Subsequent navigations continue to work normally.
Root cause
In packages/react/src/runtime/pages-client.ts, finishNavigation() rejects the visit promise when resource.commit() fails, but does not clear the active pending navigation or dispatch a failure action.
resource.commit()
.then((committed) => {
// Successful navigation cleanup.
})
.catch((error) => {
const visitSettler = pendingVisitSettlers.get(resource.id);
if (visitSettler) {
pendingVisitSettlers.delete(resource.id);
visitSettler.reject(error);
}
});
The reducer already supports fail and abandon actions that reset the navigation state, but neither is dispatched in this failure path.
Additionally, in packages/void/src/pages/navigation-engine.ts, makeCommit() modifies internal navigation state before updating browser history.
_urlNavigationId = resourceId;
// Update committed resource and deferred registry ownership.
applyClientHead(result.pageData.head as HeadDescriptor | undefined);
_currentFetchUrl = commitTarget.fetchUrl;
if (!options._popstate) {
const historyUrl = commitTarget.fetchUrl + commitTarget.hash;
scrollRestoration.writeHistory(historyUrl, !!options.replace);
}
If scrollRestoration.writeHistory() throws, the earlier internal state mutations are not rolled back, leaving the commit partially applied.
Suggested fix
- Ensure the React adapter clears the active pending navigation and dispatches the appropriate failure or rollback action when
resource.commit()rejects. - Make
makeCommit()failure-safe so that a failed history update cannot leave internal committed state inconsistent with browser history. - Ensure cleanup for a failed navigation does not overwrite or reset a newer navigation.
- Preserve existing resource lifecycle management, deferred registry ownership, and navigation ordering guarantees.
Acceptance criteria
- A failed
history.pushState()orhistory.replaceState()does not leave navigation inloadingorsubmitting. router.visit()rejects with the original error.- The browser URL, rendered page, and internal navigation state remain consistent after failure.
- Subsequent navigations work normally.
- Cleanup from an older failed navigation does not modify the state of a newer navigation.
Related issues
- #506 — preserveState prevents the destination URL from being committed (Closed)
- #507 — An older navigation can overwrite the URL after a newer navigation commits (Closed)
- #527 — Pages: actions commit the
?actionNameURL to history (Open)
Unlike these issues, this report concerns error handling and state consistency when a browser history update throws during navigation commit.
- 主要語言
- TypeScript
- 星號
- 580
- 分支
- 56
- 平均合併
- 8 小時 36 分鐘
- 30 天內合併 PR
- 110
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
voidzero-dev/void 的其他 Issue
-
Static Cloudflare deploy ignores `cloudflare.assets.html_handling`可能已有人在做 @0froq 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 77/100
voidzero-dev/void#580 ·
維護者通常 1 天內回覆
-
`void/log` serializes `Error` fields as `{}`, losing message and stack可能已有人在做 @RaphaelFakhri 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
voidzero-dev/void#577 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
voidzero-dev/void#576 ·
維護者通常 1 天內回覆
-
Dev: `better-auth/client/plugins` fails to resolve when auth is enabled (the `better-auth/client` alias matches it as a prefix)可能已有人在做 @MaxtuneLee 於 2 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
voidzero-dev/void#565 ·
維護者通常 1 天內回覆
-
prepareDeployArtifact omits worker.vars that the CLI managed deploy includes可能已有人在做 @dvkam 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
voidzero-dev/void#529 ·
維護者通常 1 天內回覆
查看 voidzero-dev/void 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
openremote/openremote#3487 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 82/100
coollabsio/jean#867 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
ehmpathy/rhachet-roles-bhuild#616 ·
維護者通常 1 天內回覆
-
📘 Docs supabase/cli
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
bug(cli): theme file home-directory check uses startsWith (sibling dirs pass, Windows casing fails)未關閉area/core kind/bug priority/p2 status/bot-triaged
難度 2/5 1-3 小時 新手友好度 79/100
google-gemini/gemini-cli#29955 · 2 則留言 ·
維護者通常 1 天內回覆