-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Invalidate HMR after route clone in router plugin #5705
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
base: main
Are you sure you want to change the base?
Conversation
Adds a call to import.meta.hot.invalidate() after cloning the Route during hot module replacement. This ensures the module is properly reloaded when routes are updated.
WalkthroughAdds an Changes
Sequence Diagram(s)sequenceDiagram
participant Vite as Vite HMR
participant RouteMod as Route Module
participant VClient as Vite Client
Vite->>RouteMod: File change -> HMR update
RouteMod->>RouteMod: import.meta.hot.accept(callback)
RouteMod->>RouteMod: newModule.Route.clone(Route)
rect rgba(220,240,255,0.35)
Note over RouteMod: New step: invalidate after clone (if clone exists)
RouteMod->>Vite: import.meta.hot?.invalidate()
end
Vite->>VClient: Trigger reload / re-evaluate modules
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (3)**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/{router-cli,router-generator,router-plugin,virtual-file-routes}/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/router-plugin/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
🔇 Additional comments (1)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/router-plugin/src/core/route-hmr-statement.ts (1)
9-9: Consider removing optional chaining for consistency.The optional chaining (
?.) is technically redundant since we're already inside theif (import.meta.hot)block at line 5, which guaranteesimport.meta.hotis truthy. You could useimport.meta.hot.invalidate()directly for consistency with line 6.Apply this diff if you prefer consistency:
- import.meta.hot?.invalidate() + import.meta.hot.invalidate()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/router-plugin/src/core/route-hmr-statement.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/router-plugin/src/core/route-hmr-statement.ts
packages/{router-cli,router-generator,router-plugin,virtual-file-routes}/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep CLI, generators, bundler plugins, and virtual file routing utilities in their dedicated tooling package directories
Files:
packages/router-plugin/src/core/route-hmr-statement.ts
packages/router-plugin/**
📄 CodeRabbit inference engine (AGENTS.md)
Use unplugin for universal bundler plugins in the router-plugin package
Files:
packages/router-plugin/src/core/route-hmr-statement.ts
🧠 Learnings (1)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad
PR: TanStack/router#5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.
Applied to files:
packages/router-plugin/src/core/route-hmr-statement.ts
🔇 Additional comments (1)
packages/router-plugin/src/core/route-hmr-statement.ts (1)
3-14: LGTM! This correctly addresses the HMR issue.The addition of
invalidate()after cloning the Route ensures that updated loader and beforeLoad functions are properly re-executed during HMR, which fixes the issue where Vite reported updates but the runtime continued using old function behavior.
Replaces 'import.meta.hot?.invalidate()' with 'import.meta.hot.invalidate()' in the route HMR statement, as 'import.meta.hot' is already checked for existence.
Adds a call to import.meta.hot.invalidate() after cloning the Route during hot module replacement. This ensures the module is properly reloaded when routes are updated.
Fixes #5698
Summary by CodeRabbit