Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.5k
fix(nuxt): track + re-add custom routes on hmr#32044
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
|
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.
Pull Request Overview
This PR addresses the issue of custom routes being lost on hot module reload by tracking manually added custom routes and re-adding them after the router updates. Key changes include:
- Capturing non-initial routes before clearing the router.
- Rebuilding the routes with generated default routes and then re-adding the captured custom routes.
- Marking routes with a _initial flag for identification after HMR.
| function addRoutes (routes) { | ||
| for (const route of routes) { | ||
| router.addRoute(route) | ||
| } | ||
| for (const route of router.getRoutes()) { | ||
| route._initial = true | ||
| } |
CopilotAIMay 8, 2025
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.
[nitpick] The _initial flag is set for all routes inside addRoutes and then similar logic runs again after the function. Consider refactoring to consolidate these loops for clarity and to avoid potential redundancy.
| functionaddRoutes(routes){ | |
| for(constrouteofroutes){ | |
| router.addRoute(route) | |
| } | |
| for(constrouteofrouter.getRoutes()){ | |
| route._initial=true | |
| } | |
| functionmarkRoutesAsInitial(router){ | |
| for(constrouteofrouter.getRoutes()){ | |
| route._initial=true | |
| } | |
| } | |
| functionaddRoutes(routes){ | |
| for(constrouteofroutes){ | |
| router.addRoute(route) | |
| } | |
| markRoutesAsInitial(router) |
| } | ||
| for (const route of router.getRoutes()) { | ||
| route._initial = true | ||
| } |
CopilotAIMay 8, 2025
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.
[nitpick] It is not immediately clear why custom routes captured in addedRoutes are re-added after marking existing routes as _initial. Adding an inline comment to explain this logic would improve code clarity.
| } | |
| } | |
| // Re-add custom routes (addedRoutes) to ensure they are preserved | |
| // after clearing and re-initializing the router's routes. |
WalkthroughThe hot module replacement (HMR) process for route updates in the router has been updated to better handle dynamically added routes. The new logic captures all routes without the Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (3)
✨ 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. 🪧 TipsChatThere are 3 ways to chat withCodeRabbit:
SupportNeed help? Create a ticket on oursupport page for assistance with any issues or questions. 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 ( |
@nuxt/kitnuxt@nuxt/rspack-builder@nuxt/schema@nuxt/vite-builder@nuxt/webpack-buildercommit: |
CodSpeed Performance ReportMerging#32044 willnot alter performanceComparing Summary
|
🔗 Linked issue
resolves#32027
📚 Description
this tracks what routes have been manually added, and re-adds them when we HMR the router