-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: trigger navigation guards when keep-alive component is reactivated for different route #2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ted for different route
✅ Deploy Preview for vue-router canceled.
|
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughRefactors guard registration to use a ComputedRef for the active route record so guards can be re-registered when a KeepAlive-wrapped component is reactivated for a different route. Adds tests for onBeforeRouteLeave and onBeforeRouteUpdate covering shared KeepAlive components and tracks activation/deactivation and guard invocation/registration. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Router as Router
participant KeepAlive as KeepAlive
participant Component as Component
participant GuardRegistry as Guard Registry
participant RouteRecord as Route Record
Client->>Router: navigate(to Route A)
Router->>KeepAlive: render/update <rgba(100,150,240,0.5)>
KeepAlive->>Component: mount / onActivated
Component->>GuardRegistry: registerGuard(computedActiveRecordRef)
GuardRegistry->>RouteRecord: resolve currentRecord from ref
GuardRegistry->>RouteRecord: attach guard to currentRecord
Client->>Router: navigate(to Route B, same kept component)
Router->>KeepAlive: update (component kept alive) <rgba(180,120,200,0.5)>
KeepAlive->>Component: onDeactivated -> onActivated
Component->>GuardRegistry: resolve currentRecord from ref
GuardRegistry->>RouteRecord: detect new record
GuardRegistry->>RouteRecord: remove guard from old, attach to new
Client->>Router: route params/query update
Router->>GuardRegistry: invoke guards for currentRecord
GuardRegistry-->>Router: guard result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
commit: |
posva
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2604 +/- ##
==========================================
+ Coverage 91.27% 91.54% +0.27%
==========================================
Files 46 46
Lines 4181 4188 +7
Branches 1114 1116 +2
==========================================
+ Hits 3816 3834 +18
+ Misses 358 347 -11
Partials 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@packages/router/__tests__/guards/onBeforeRouteLeave.spec.ts`:
- Around line 77-79: Update the Step 2 comment to accurately describe the
navigation: change the text that currently says navigating to `/a/123` to
reflect that the test actually calls `await router.push('/other')` (e.g., "Step
2: Navigate to /other - SharedComponent is deactivated (kept alive); Leave guard
is called when leaving /a"). This ensures the comment next to the `await
router.push('/other')` line matches the action being performed.
In `@packages/router/__tests__/guards/onBeforeRouteUpdate.spec.ts`:
- Around line 120-123: Update the inline comment that currently reads "// BUG:
The guard was registered with /a's record, not /b's record // So when /b
updates, the guard is not called" to clearly state this is the pre-fix behavior
and contrasts with the test assertion; reference the router.push('/b?page=2')
step and onBeforeRouteUpdate guard so the comment reads that before the fix the
guard was registered to /a (so updating /b did not trigger it), whereas the test
now asserts the guard is called after the fix.
|
@posva |
fixes #2601
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.