fix(runtime-utils): provide NuxtLink isActive slot props#1640
fix(runtime-utils): provide NuxtLink isActive slot props#1640Archetipo95 wants to merge 4 commits intonuxt:mainfrom
Conversation
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe changes add a new example Vue component (NuxtLinkWithIsActive.vue) and two example pages (/about and /about/team). Tests were added to assert NuxtLink custom-slot active-state behavior using mountSuspended. The RouterLink runtime was modified to use useLink(props) (instead of useRouter()), derive route, href, isActive, and isExactActive from the returned link, and to pass Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
examples/app-vitest-full/tests/nuxt/mount-suspended.spec.ts (1)
551-552: Prefer deterministic link selection in assertions.Using text-search over all anchors is a bit brittle. Selecting the About anchor by
hrefmakes these tests more stable.Suggested refinement
- const aboutLink = component.findAll('a').find(el => el.text().includes('About')) - expect(aboutLink?.classes()).toContain('active') + const aboutLink = component.get('a[href="/about"]') + expect(aboutLink.classes()).toContain('active') ... - const aboutLink = component.findAll('a').find(el => el.text().includes('About')) - expect(aboutLink?.classes()).not.toContain('active') + const aboutLink = component.get('a[href="/about"]') + expect(aboutLink.classes()).not.toContain('active')Also applies to: 560-561
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@examples/app-vitest-full/tests/nuxt/mount-suspended.spec.ts` around lines 551 - 552, Replace the brittle text-based anchor lookup (aboutLink = component.findAll('a').find(el => el.text().includes('About'))) with a deterministic selector that targets the About link by its href attribute (use component.find or component.findAll with 'a[href="/about"]'), then assert its classes() contains 'active'; update the same pattern at the other occurrence that currently uses text-search to ensure stable tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/runtime-utils/components/RouterLink.ts`:
- Around line 25-26: The two flags are incorrectly identical; change the
assignment so isActive checks whether the link's route record appears anywhere
in the currentRoute.matched hierarchy (e.g., use
currentRoute.matched.some(record => record === route || record.name ===
route.name)), while isExactActive remains the exact route match (e.g., compare
route.path or route.name to currentRoute.path/name). Update the variables
isActive and isExactActive in the RouterLink component to use these distinct
checks referencing route and currentRoute.
---
Nitpick comments:
In `@examples/app-vitest-full/tests/nuxt/mount-suspended.spec.ts`:
- Around line 551-552: Replace the brittle text-based anchor lookup (aboutLink =
component.findAll('a').find(el => el.text().includes('About'))) with a
deterministic selector that targets the About link by its href attribute (use
component.find or component.findAll with 'a[href="/about"]'), then assert its
classes() contains 'active'; update the same pattern at the other occurrence
that currently uses text-search to ensure stable tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f0ca9886-c1bf-4aa5-85da-124731e6fd2c
📒 Files selected for processing (3)
examples/app-vitest-full/components/NuxtLinkWithIsActive.vueexamples/app-vitest-full/tests/nuxt/mount-suspended.spec.tssrc/runtime-utils/components/RouterLink.ts
use vue-router useLink in RouterLink mock track nested-route NuxtLink-in-suspended limitation via expected-fail regression test
|
Im not sure if I can tag @coderabbitai, but the latest commit has the fix for One known limitation came up in testing. When This happens because A proper fix would likely need to happen in VTU or in |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 1848 🏁 Script executed: Length of output: 36534
On the primary fix: Using On the nested route limitation: The root cause you've identified is accurate. NuxtLink checks for a A few potential avenues worth considering:
Given the complexity, the (´• ω •`) 🐇 ✏️ Learnings added
|
Linked issue
Closes #1042
Description
This fixes NuxtLink custom slot behavior in
mountSuspendedby providingisActiveandisExactActiveslot props from the RouterLink test stub.isActiveandisExactActivein custom-slot modev-slot="{ isActive }"usageValidation
VITEST_DOM_ENV=happy-dom pnpm test:unit --runVITEST_DOM_ENV=jsdom pnpm test:unit --run