perf(nuxt): disable NuxtLink visibility prefetching in dev mode#34325
Merged
perf(nuxt): disable NuxtLink visibility prefetching in dev mode#34325
Conversation
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.
|
|
Contributor
WalkthroughThe 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)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
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.
danielroe
approved these changes
Feb 13, 2026
Closed
Merged
Closed
danielroe
pushed a commit
that referenced
this pull request
Mar 9, 2026
Merged
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 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 whenimport.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)