Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/nuxtPublic

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

Draft
danielroe wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromfix/custom-route-hmr

Conversation

@danielroe
Copy link
Member

🔗 Linked issue

resolves#32027

📚 Description

this tracks what routes have been manually added, and re-adds them when we HMR the router

CopilotAI review requested due to automatic review settingsMay 8, 2025 18:03
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz CodeflowRun & review this pull request inStackBlitz Codeflow.

Copy link

CopilotAI left a 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.

Comment on lines 678 to +684
function addRoutes (routes) {
for (const route of routes) {
router.addRoute(route)
}
for (const route of router.getRoutes()) {
route._initial = true
}
Copy link

CopilotAIMay 8, 2025

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
}
for (const route of router.getRoutes()) {
route._initial = true
}
Copy link

CopilotAIMay 8, 2025

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.

Suggested change
}
}
// Re-add custom routes (addedRoutes) to ensure they are preserved
// after clearing and re-initializing the router's routes.

Copilot uses AI. Check for mistakes.
@coderabbitai
Copy link

Walkthrough

The 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_initial flag before clearing the router's routes during HMR. After regenerating and adding the new routes, it marks all current routes as_initial and then restores the previously captured non-initial routes. This approach ensures dynamically added routes are retained during HMR updates. Additionally, during HMR data initialisation, all existing routes are now marked with_initial = true to distinguish them from dynamically added routes in subsequent updates.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configureReview - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off theData Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and betweend79e146 andb4df079.

📒 Files selected for processing (1)
  • packages/nuxt/src/pages/module.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (3)
packages/nuxt/src/pages/module.ts (3)

675-675:Good implementation for capturing dynamically added routes.

The new code elegantly captures all routes that don't have the_initial flag before the router is cleared. This ensures that dynamically added routes (those without the flag) are preserved during Hot Module Replacement.


682-687:Well-structured solution for maintaining custom routes through HMR cycles.

This implementation properly:

  1. Marks all newly generated routes as_initial = true
  2. Re-adds previously captured non-initial routes to the router

This approach ensures that manually added routes persist correctly during development without requiring a full reload, addressing the issue described in the PR objectives.


703-705:Good initialization of route tracking.

Marking all existing routes with_initial = true during HMR data initialization is a critical part of this solution. It establishes the baseline for identifying which routes were added programmatically versus those that were part of the initial configuration.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat withCodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag@coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag@coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings togenerate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add@coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add@coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add@coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a.coderabbit.yaml file to the root of your repository.
  • Please see theconfiguration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit ourDocumentation for detailed information on how to use CodeRabbit.
  • Join ourDiscord Community to get help, request features, and share feedback.
  • Follow us onX/Twitter for updates and announcements.

@pkg-pr-new
Copy link

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@32044

nuxt

npm i https://pkg.pr.new/nuxt@32044

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@32044

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@32044

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@32044

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@32044

commit:b4df079

@codspeed-hq
Copy link

CodSpeed Performance Report

Merging#32044 willnot alter performance

Comparingfix/custom-route-hmr (b4df079) withmain (d79e146)

Summary

✅ 10 untouched benchmarks

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

Copilot code reviewCopilotCopilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

custom routes added are erased after HMR

1 participant

@danielroe

[8]ページ先頭

©2009-2025 Movatter.jp