Skip to content

fix(Link): wait for onNuxtReady before observing visibility - #6922

Merged
benjamincanac merged 1 commit into
v4from
fix/link-prefetch-nuxt-ready
Sep 5, 2026
Merged

fix(Link): wait for onNuxtReady before observing visibility#6922
benjamincanac merged 1 commit into
v4from
fix/link-prefetch-nuxt-ready

Conversation

@benjamincanac

Copy link
Copy Markdown
Member

🔗 Linked issue

Follow-up to #6921

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Before Nuxt 4.5, NuxtLink observed custom links itself and only started the visibility observer inside onNuxtReady. #6921 rebuilt that observer in ULink but scheduled it straight from onMounted, so ULink started prefetching earlier than a plain NuxtLink.

This matters for two reasons:

  • the nuxt:payload plugin registers its link:prefetch listener inside onNuxtReady, and prefetch() marks the link as prefetched before calling the hook. If a plugin ordered before nuxt:payload returns a promise from app:suspense:resolve, an early visible link can fire before the listener exists and never loads its payload.
  • Nuxt gates prefetching on onNuxtReady on purpose so payload and chunk requests don't compete with hydration.

ULink now mirrors NuxtLink again: onMountedonNuxtReadyrequestIdleCallback → observe, with a guard so a link unmounted before hydration resolves never starts an observer.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@github-actions github-actions Bot added the v4 #4488 label Sep 5, 2026
@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 9d36e2da-d58a-4a20-b73a-974cd6abdb08

📥 Commits

Reviewing files that changed from the base of the PR and between fbb9e22 and 7b7744d.

📒 Files selected for processing (1)
  • src/runtime/components/Link.vue

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Link prefetching now waits for onNuxtReady before scheduling idle work and intersection observation. The component tracks its unmounted state and skips scheduling after teardown. Unmount handling marks the component as unmounted, cancels pending idle work, and disconnects the observer.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 7b774

ULink prefetching now waits until Nuxt is ready, avoiding hydration-time request contention while retaining cleanup on unmount. The change is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the ULink prefetch timing fix, its relation to NuxtLink, and the unmount guard.
Title check ✅ Passed The title clearly and concisely identifies the main change: delaying Link visibility observation until onNuxtReady.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/link-prefetch-nuxt-ready

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/runtime/components/Link.vue

Parsing error: Unexpected token )


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.

@codspeed-hq

codspeed-hq Bot commented Sep 5, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing fix/link-prefetch-nuxt-ready (7b7744d) with v4 (fbb9e22)

Open in CodSpeed

@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/ui@6922

commit: 7b7744d

@benjamincanac
benjamincanac merged commit 612ab1c into v4 Sep 5, 2026
27 checks passed
@benjamincanac
benjamincanac deleted the fix/link-prefetch-nuxt-ready branch September 5, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v4 #4488

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant