-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
fix(nuxt): hook called twice during navigation #29009
base: main
Are you sure you want to change the base?
Conversation
Run & review this pull request in StackBlitz Codeflow. |
Would you be able to add some regression tests for this? 🙏 (And also to confirm that we don't reintroduce the issue that PR was resolving.) |
@danielroe I did a test |
@danielroe thanks your test refactoring |
@danielroe do you need anything else for this PR? |
apologies for not commenting! i was planning to add a regression test to show that this reintroduces the bug where the loading indicator shows permanently after hitting the browser back button any chance you could have a look? |
@danielroe |
WalkthroughThe pull request introduces several modifications to the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 0
🧹 Outside diff range and nitpick comments (3)
test/fixtures/basic/plugins/page-hook-plugin.ts (2)
1-2
: Consider adding TypeScript types for better type safety.Adding explicit types would improve code maintainability and catch potential issues early.
-export default defineNuxtPlugin((nuxtApp) => { +export default defineNuxtPlugin((nuxtApp: any) => {
1-8
: Add JSDoc documentation to explain the plugin's test purpose.Since this is a test fixture, adding documentation would help other developers understand its role in testing the hook behavior.
+/** + * Test plugin for verifying page:loading:end hook behavior. + * Logs hook execution only for the /page-load-hook route. + * Used in conjunction with basic.test.ts to ensure the hook fires exactly once. + */ export default defineNuxtPlugin((nuxtApp) => {test/fixtures/basic/pages/index.vue (1)
97-99
: LGTM! Consider adding data-testid for better test targeting.The new NuxtLink addition is well-placed and follows the existing patterns. To improve test reliability, consider adding a data-testid attribute.
- <NuxtLink to="/page-load-hook"> + <NuxtLink + data-testid="page-load-hook-link" + to="/page-load-hook" + >
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
packages/nuxt/src/pages/runtime/page.ts
(0 hunks)test/basic.test.ts
(1 hunks)test/fixtures/basic/pages/index.vue
(1 hunks)test/fixtures/basic/pages/page-load-hook.vue
(1 hunks)test/fixtures/basic/plugins/page-hook-plugin.ts
(1 hunks)
💤 Files with no reviewable changes (1)
- packages/nuxt/src/pages/runtime/page.ts
✅ Files skipped from review due to trivial changes (1)
- test/fixtures/basic/pages/page-load-hook.vue
🔇 Additional comments (3)
test/fixtures/basic/plugins/page-hook-plugin.ts (2)
1-8
: LGTM! The plugin implementation looks correct for testing purposes.
The plugin correctly implements the hook listener for verifying the page:loading:end
event behavior.
3-7
: Consider adding additional test scenarios.
The current implementation only tests for a single route. Consider expanding the test coverage to include:
- Different route scenarios
- Navigation timing verification
- Hook execution order validation
test/basic.test.ts (1)
629-638
: LGTM! Well-structured test case for verifying hook behavior.
The test case effectively verifies that the page:loading:end
hook is triggered only once during navigation. It follows testing best practices with proper setup, clear assertions, and cleanup.
to be clear, this causes a regression of #25039 which needs to be resolved before it can be merged. you can reproduce with https://stackblitz.com/edit/nuxt-starter-r5biil?file=pages%2Fuser.vue. |
🔗 Linked issue
resolves #26535
📚 Description
This PR: #25932 (custom loading reset/hide delay + force finish()) solved this early fix: #24931 (stop loading indicator if page keys are the same) issue.
But this PR (#25932) generated another error: hook called twice during navigation.
I have removed this code which is no longer needed and also causes an error.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
page:loading:end
event is triggered only once during navigation.