Skip to content

feat(theme/Link): support awaited navigation - #3592

Open
SoonIter wants to merge 1 commit into
mainfrom
feat/awaited-navigation
Open

feat(theme/Link): support awaited navigation#3592
SoonIter wants to merge 1 commit into
mainfrom
feat/awaited-navigation

Conversation

@SoonIter

@SoonIter SoonIter commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

Add useAwaitedLinkNavigate for integrations that need to know when an internal route has committed. Navigation calls are serialized, preserve query and hash values, support cancellation, and recover after preload failures or timeouts.

Context

Extracted from #3520 as an independently reviewable Core prerequisite. The other prerequisites split from that PR are #3590 and #3591.

Related Issue

N/A

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI lite review requested due to automatic review settings August 7, 2026 07:55
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rspress-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1e41da1
Status: ✅  Deploy successful!
Preview URL: https://11901d20.rspress-v2.pages.dev
Branch Preview URL: https://feat-awaited-navigation.rspress-v2.pages.dev

View logs

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 4 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
website_html 14.2 MB 2.0 MB 0 +194.0 B (0.0%)
website_md 1.8 MB 262.4 KB 0 0
website_js 16.7 MB 2.9 MB +216.0 B (0.0%) +54.0 B (0.0%)
auto_nav_sidebar_html 447.5 KB 93.4 KB 0 +16.0 B (0.0%)
auto_nav_sidebar_js 544.3 KB 171.5 KB +218.0 B (0.0%) +52.0 B (0.0%)
📋 Detailed Reports (Click to expand)

📁 website_html

Path: website/doc_build/diff-rsdoctor/website_html/rsdoctor-data.json

📌 Baseline Commit: a607897b51 | PR: #3588

Metric Current Baseline Change
📊 Total Size 14.2 MB 14.2 MB 0
🗜️ Gzip Size 2.0 MB 2.0 MB +194.0 B (0.0%)
📄 JavaScript 0 B 0 B 0
🎨 CSS 0 B 0 B 0
🌐 HTML 14.2 MB 14.2 MB 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: website_html Bundle Diff

📁 website_js

Path: website/doc_build/diff-rsdoctor/website_js/rsdoctor-data.json

📌 Baseline Commit: a607897b51 | PR: #3588

Metric Current Baseline Change
📊 Total Size 16.7 MB 16.7 MB +216.0 B (0.0%)
🗜️ Gzip Size 2.9 MB 2.9 MB +54.0 B (0.0%)
📄 JavaScript 16.4 MB 16.4 MB +216.0 B (0.0%)
🎨 CSS 140.7 KB 140.7 KB 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 172.9 KB 172.9 KB 0

📦 Download Diff Report: website_js Bundle Diff

📁 auto_nav_sidebar_html

Path: e2e/fixtures/auto-nav-sidebar/doc_build/diff-rsdoctor/auto_nav_sidebar_html/rsdoctor-data.json

📌 Baseline Commit: a607897b51 | PR: #3588

Metric Current Baseline Change
📊 Total Size 447.5 KB 447.5 KB 0
🗜️ Gzip Size 93.4 KB 93.4 KB +16.0 B (0.0%)
📄 JavaScript 0 B 0 B 0
🎨 CSS 0 B 0 B 0
🌐 HTML 447.5 KB 447.5 KB 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: auto_nav_sidebar_html Bundle Diff

📁 auto_nav_sidebar_js

Path: e2e/fixtures/auto-nav-sidebar/doc_build/diff-rsdoctor/auto_nav_sidebar_js/rsdoctor-data.json

📌 Baseline Commit: a607897b51 | PR: #3588

Metric Current Baseline Change
📊 Total Size 544.3 KB 544.1 KB +218.0 B (0.0%)
🗜️ Gzip Size 171.5 KB 171.5 KB +52.0 B (0.0%)
📄 JavaScript 473.7 KB 473.5 KB +218.0 B (0.0%)
🎨 CSS 64.0 KB 64.0 KB 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 6.6 KB 6.6 KB 0

📦 Download Diff Report: auto_nav_sidebar_js Bundle Diff

Generated by Rsdoctor GitHub Action

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e41da1d4e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

} else {
preloadChunkThenNavigate();
}
await preloadChunkThenNavigate();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the preload inside the supplied transition

When route.useTransitions is enabled and Link receives useTransition().startTransition, awaiting preloadChunkThenNavigate() directly moves the potentially slow initPageData phase outside that transition. Consequently, the documented isPending state remains false until preloading finishes, so loading feedback disappears during most of a slow navigation; this reverses the async-transition handling intentionally added in commit 2587f69. Preserve the outer transition around the asynchronous preload while separately settling the promise returned by useLinkNavigate.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the core theme navigation utilities by adding an awaited navigation hook intended for integrations that need to know when an internal route transition has committed, while also enhancing existing link navigation to preserve query/hash for relative URLs and support cancellation.

Changes:

  • Export a new useAwaitedLinkNavigate hook from @rspress/core/theme for commit-aware, serialized navigation.
  • Update useLinkNavigate to preserve search/hash on relative URLs and accept an optional AbortSignal for cancellation.
  • Add a unit test for getAwaitedTarget and publish the change via a changeset.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/core/src/theme/index.ts Re-exports the new awaited navigation hook alongside useLinkNavigate.
packages/core/src/theme/components/Link/useLinkNavigate.ts Adds awaited/serialized navigation logic and AbortSignal support; fixes relative href handling to preserve query/hash.
packages/core/src/theme/components/Link/useLinkNavigate.test.ts Adds tests for canonical awaited target resolution.
.changeset/calm-navigation-await.md Declares a minor release for the new awaited navigation hook.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +184 to +189
const navigateAndWait = useCallback(
async (href: string, target: string) => {
if (currentTargetRef.current === target) {
await navigate(href);
return;
}
Comment on lines +236 to +253
return useCallback(
(target: string) => {
const queued = queueRef.current
.catch(() => undefined)
.then(() => {
if (!activeRef.current) {
throw new Error('Navigation was interrupted');
}
return navigateAndWait(
target,
getAwaitedTarget(target, currentTargetRef.current),
);
});
queueRef.current = queued;
return queued;
},
[navigateAndWait],
);
Comment on lines +149 to +156
/**
* Navigate through the Rspress router and resolve after the target location
* commits. Calls are serialized and failed or timed-out attempts do not
* block later calls.
*/
export function useAwaitedLinkNavigate(
committedTarget?: string,
): (href: string) => Promise<void> {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants