Skip to content

fix(navigation): avoid redundant route requests - #11

Merged
yororoA merged 1 commit into
mainfrom
fix/navigation-prefetch
Oct 10, 2026
Merged

yororoA merged 1 commit into
mainfrom
fix/navigation-prefetch

Conversation

@yororoA

@yororoA yororoA commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

修复预请求触发大量路由RSC导致的页面跳转卡顿

Summary by Sourcery

Reduce redundant navigation requests and defer route prefetching until user intent to improve page-transition responsiveness.

Bug Fixes:

  • Reduce redundant route and reference-data requests during navigation to prevent page-transition lag from excessive RSC prefetching.

Enhancements:

  • Enable stale-time caching for dynamic and static Next.js content.
  • Make custom navigation links prefetch only after user intent is shown through hover or focus.
  • Treat blog categories and sitemap data as non-revalidating reference data.
  • Move the home page into the blog route group and add SEO metadata.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Reduces redundant route and data requests by delaying default Next.js link prefetching until hover or focus, preventing repeated SWR revalidation for stable reference data, and configuring route stale times; the home route is also consolidated into the blog route group with explicit metadata.

Sequence diagram for intent-based navigation prefetching

sequenceDiagram
    participant User
    participant P3RLink
    participant NextRouter
    participant Route

    User->>P3RLink: onMouseEnter()
    P3RLink->>P3RLink: setPrefetchOnIntent(true)
    P3RLink->>NextRouter: prefetch(route)
    NextRouter->>Route: request RSC
    User->>P3RLink: onClick()
    P3RLink->>NextRouter: navigate(route)
Loading

File-Level Changes

Change Details Files
Defer automatic link prefetching until the user shows navigation intent.
  • Track hover/focus intent for links without an explicit prefetch prop.
  • Preserve explicit prefetch behavior while disabling default prefetch until intent is detected.
  • Continue forwarding existing event handlers and transition/navigation props.
src/components/appearance/p3r-link.tsx
Cache reference data without repeated background revalidation.
  • Add a dedicated SWR hook with focus, reconnect, and stale revalidation disabled.
  • Use the reference-data hook for article categories and archive sitemap data.
src/components/blog/blog-provider.tsx
src/components/blog/articles.tsx
src/components/blog/moments.tsx
Configure Next.js route data retention and consolidate the home route metadata.
  • Set dynamic and static stale times to 30 and 300 seconds.
  • Move the home page into the blog route group and define SEO metadata there.
  • Remove the former home layout and loading files.
next.config.ts
src/app/(blog)/home/page.tsx
src/app/home/layout.tsx
src/app/home/loading.tsx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@vercel

vercel Bot commented Oct 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ark Ready Ready Preview Oct 10, 2026 10:45am UTC

@yororoA
yororoA merged commit 65630bf into main Oct 10, 2026
5 checks passed
@yororoA
yororoA deleted the fix/navigation-prefetch branch October 10, 2026 10:45

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Needs a human reviewer. If the caching policy or reference-data behavior is wrong, users can see stale routes, categories, or sitemap data because client route caches and SWR caches outlive the deployment change. Reverting restores the previous behavior, but it does not immediately evict already-populated caches; they must expire, be reloaded, or be cleared.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch was successfully deployed

1 active deployment
Preview — 92861956 Deployed Oct 10, 2026 by vercel[bot]
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.

1 participant