-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(nuxt): re-execute callOnce during HMR #33810
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
|
|
@nuxt/kit
@nuxt/nitro-server
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #33810 will not alter performanceComparing Summary
|
WalkthroughThis change adds a module-scoped boolean flag to Possibly related PRs
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 (2)**/*.{ts,tsx,vue}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
**/*.{ts,tsx,js,jsx,vue}📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Files:
🧠 Learnings (2)📚 Learning: 2024-12-12T12:36:34.871ZApplied to files:
📚 Learning: 2025-11-25T11:42:16.132ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (3)
Tip ✨ Issue Enrichment is now available for GitHub issues!CodeRabbit can now help you manage issues more effectively:
Disable automatic issue enrichmentTo disable automatic issue enrichment, add the following to your issue_enrichment:
auto_enrich:
enabled: falseThanks 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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/nuxt/src/app/composables/once.ts(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,vue}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/nuxt/src/app/composables/once.ts
**/*.{ts,tsx,js,jsx,vue}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently
Files:
packages/nuxt/src/app/composables/once.ts
🧠 Learnings (1)
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
Repo: nuxt/nuxt PR: 29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:
```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```
instead of wrapping the import in a computed property or importing the component unconditionally.
Applied to files:
packages/nuxt/src/app/composables/once.ts
🔇 Additional comments (2)
packages/nuxt/src/app/composables/once.ts (2)
8-9: LGTM: Module-scoped HMR flag is appropriate.The module-scoped flag is a reasonable approach for tracking HMR state in development mode.
59-71: This HMR event listener implementation appears sound and does not have the timing issues described.The concerns raised in the original review conflate the intended behavior with potential problems. Here's the verification:
Timing window is intentional: The
vite:beforeUpdate→vite:afterUpdatewindow where_isHmrUpdating = trueexists specifically to allowcallOnceto re-execute when a module is hot-replaced. When Vite replaces a module containing acallOncecall, the developer expects it to run again during development. This is not a race condition but a feature.Listener lifecycle is safe: Vite's HMR API manages the lifecycle of
import.meta.hot. These listeners are part of the module's hot context and do not leak when the module is replaced. The guardif (import.meta.hot)is the standard pattern.Event filtering is correct: Filtering for
'js-update'type is appropriate. CSS and other non-JS updates should not resetcallOncebehavior; only JavaScript module changes should trigger re-execution.The implementation follows Vite's documented HMR patterns correctly and is protected by the
import.meta.devcheck (line 45), ensuring this re-execution only occurs in development.
|
Wouldn't this re-execute on any javascript HMR update, though? |
Co-authored-by: Daniel Roe <daniel@roe.dev>
If Component A with |
🔗 Linked issue
fix #33788
📚 Description
This PR re-executes
callOnceduring HMR.