Skip to content

perf(nuxt): disable NuxtLink visibility prefetching in dev mode#34325

Merged
danielroe merged 5 commits intomainfrom
fix/disable-prefetch-dev
Feb 13, 2026
Merged

perf(nuxt): disable NuxtLink visibility prefetching in dev mode#34325
danielroe merged 5 commits intomainfrom
fix/disable-prefetch-dev

Conversation

@harlan-zw
Copy link
Copy Markdown
Contributor

@harlan-zw harlan-zw commented Feb 13, 2026

🔗 Linked issue

📚 Description

All page chunks are lazy in Nuxt. When we hit a page chunk and Vite finds dependencies that it wasn't able to find on the initial crawl, it can cause a reload.

When we load a Nuxt page and we preload NuxtLink's based on visibility, this leads to several unoptimized dependencies discovered as we try and use the page. As these optimizations can feel a bit cryptic, it's not clear to end users what's going on, it just feels buggy.

This is partially helped with #34320

To resolve this we can stop preloading in dev. This means that if a user navigates to a page for a dependency they don't have, it triggers a reload as they access the page. Still annoying but less disruptive.

Route prefetching has negligible value in dev, so shouldPrefetch() now returns early when import.meta.dev. We do lose some environmental parity which is a concern and worth discussing if the trade-off is worth it.

This should visualize how annoying it is https://stackblitz.com/edit/nuxt-starter-tfkhuqhq?file=app%2Fpages%2Findex.vue

Alternative: Maybe set a small window where we can preload links < 500ms before any meaningful interaction (i.e above the fold links are prefetched)

Vite's dependency optimizer triggers a full page reload whenever it
discovers a new dependency after the initial crawl. In dev, NuxtLink's
prefetch (via IntersectionObserver/interaction) imports page chunks for
routes the user isn't on, which can discover unbundled deps and reload
the current page — losing component state.

Route prefetching has negligible value in dev (localhost latency is
instant), so skip it entirely:
- `preloadRouteComponents` returns early when `import.meta.dev`
- prefetch plugin skips `link:prefetch` hook registration in dev

Layout loading on actual navigation (`router.beforeEach`) is preserved.
NuxtLink's shouldPrefetch already returns early in dev, so link:prefetch
is never emitted and the plugin guard is unnecessary.
@harlan-zw harlan-zw requested a review from danielroe as a code owner February 13, 2026 07:23
@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 13, 2026

Walkthrough

The prefetch logic in the Nuxt Link component now includes an additional development mode guard. The preload path will not execute when in development mode, alongside existing conditions that prevent preloading for external links or targeted content. This guard condition has been added to the existing check logic without modifying other control flow operations.

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Title check ✅ Passed The title clearly and specifically summarizes the main change: disabling NuxtLink prefetching in development mode to improve developer experience by reducing unnecessary reloads.
Description check ✅ Passed The pull request description clearly explains the motivation, problem statement, and solution related to disabling route prefetching in development mode to reduce Vite dependency discovery reloads.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/disable-prefetch-dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 13, 2026

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@34325

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@34325

nuxt

npm i https://pkg.pr.new/nuxt@34325

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@34325

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@34325

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@34325

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@34325

commit: 8a1bd1e

@danielroe danielroe moved this to Discussing in Team Board Feb 13, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 13, 2026

Merging this PR will not alter performance

✅ 21 untouched benchmarks


Comparing fix/disable-prefetch-dev (8a1bd1e) with main (6abf310)

Open in CodSpeed

Prefetch is now disabled in dev, so the test waiting for a prefetched
payload request will time out.
Payload prefetch (JSON) doesn't trigger Vite dep discovery — only
preloadRouteComponents (JS chunk imports) does. Move the dev guard to
the specific call site instead of shouldPrefetch.
@harlan-zw harlan-zw changed the title perf: disable route prefetching in dev mode perf: disable NuxtLink visibility prefetching in dev mode Feb 13, 2026
@harlan-zw harlan-zw marked this pull request as draft February 13, 2026 08:11
@harlan-zw harlan-zw marked this pull request as ready for review February 13, 2026 08:21
@danielroe danielroe changed the title perf: disable NuxtLink visibility prefetching in dev mode perf(nuxt): disable NuxtLink visibility prefetching in dev mode Feb 13, 2026
@danielroe danielroe added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit 8a01eac Feb 13, 2026
66 checks passed
@danielroe danielroe deleted the fix/disable-prefetch-dev branch February 13, 2026 14:45
@github-project-automation github-project-automation bot moved this from Discussing to Later in Team Board Feb 13, 2026
@github-actions github-actions bot mentioned this pull request Feb 12, 2026
@github-actions github-actions bot mentioned this pull request Feb 24, 2026
@github-actions github-actions bot mentioned this pull request Mar 8, 2026
@github-actions github-actions bot mentioned this pull request Mar 9, 2026
@github-actions github-actions bot mentioned this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Later

Development

Successfully merging this pull request may close these issues.

2 participants