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
- 星标
- 402
- 派生
- 32
- 平均合并
- 8 小时 32 分钟
- 30 天内合并 PR
- 111
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
voidzero-dev/void 的其他 Issue
-
Dev: `better-auth/client/plugins` fails to resolve when auth is enabled (the `better-auth/client` alias matches it as a prefix)可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
voidzero-dev/void#565 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
voidzero-dev/void#529 ·
维护者通常 1 天内回复
-
bug
难度 1/5 1-3 小时 新手友好度 78/100
voidzero-dev/void#428 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 53/100
voidzero-dev/void#567 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
voidzero-dev/void#564 ·
维护者通常 1 天内回复
查看 voidzero-dev/void 的全部 Issue
相似的 Issue
-
area:desktop bug documentation
难度 2/5 1-3 小时 新手友好度 76/100
anthropics/claude-code#104801 ·
维护者通常 1 天内回复
-
check:passed streams:add
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
spudly/design-system#110 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
[Bug]: REST API URL starting with "http" but no scheme (e.g. httpbin.org/get) is not given an http:// prefix可能已有人在做 @ItsDeadlyProgrammer 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
appsmithorg/appsmith#42471 · 1 条评论 ·
维护者通常 2 天内回复