-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
fix(kit): add default values for destructured references in addTypeTemplate hooks #33239
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(kit): add default values for destructured references in addTypeTemplate hooks #33239
Conversation
|
|
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
WalkthroughThe change modifies packages/kit/src/template.ts to stop destructuring hook payloads and instead accept a single Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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). (2)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. 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: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/kit/src/template.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/kit/src/template.ts
⏰ 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). (17)
- GitHub Check: test-fixtures (windows-latest, dev, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (windows-latest, built, rspack, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, lts/-1)
- GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
- GitHub Check: release-pkg-pr-new
- GitHub Check: typecheck (ubuntu-latest, bundler)
- GitHub Check: test-benchmark
- GitHub Check: typecheck (windows-latest, bundler)
- GitHub Check: test-size
- GitHub Check: code
CodSpeed Performance ReportMerging #33239 will not alter performanceComparing Summary
|
danielroe
left a 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.
coderabbit makes a good point - shall we mutate the payload instead of creating a new array?
yes, the suggestions are good. The current approach with destructuring creates new local variables that don't mutate the original payload, which means the pushed references get lost. Let me apply thm |
…mplate hooks Fixes issue where nodeReferences, sharedReferences, and references arrays could be undefined when destructured in prepare:types and nitro:prepare:types hooks, causing 'Cannot read properties of undefined (reading "push")' errors. This ensures backward compatibility by providing empty arrays as defaults when the hook payload doesn't contain these properties.
6e3b606 to
df8c4f7
Compare
I've applied all the suggestions to fix the payload mutation issue and updated the existing commit instead of creating a new one. It now mutates the payload object instead of creating local variables and uses the |
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 (4)
packages/kit/src/template.ts (4)
83-85: Prefer nullish assignment over logical ORUse ??= to only initialise when the field is null/undefined (avoids clobbering any rare falsy-but-valid values).
- (payload.references ||= []).push({ path: template.dst }) + (payload.references ??= []).push({ path: template.dst })
88-90: Apply the same nullish assignment hereConsistency and slightly safer semantics.
- (payload.nodeReferences ||= []).push({ path: template.dst }) + (payload.nodeReferences ??= []).push({ path: template.dst })
93-95: Apply the same nullish assignment hereKeeps behaviour consistent across all reference arrays.
- (payload.sharedReferences ||= []).push({ path: template.dst }) + (payload.sharedReferences ??= []).push({ path: template.dst })
108-110: And for Nitro types as wellMirror the same pattern in the Nitro hook.
- (payload.references ||= []).push({ path: template.dst }) + (payload.references ??= []).push({ path: template.dst })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/kit/src/template.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Follow standard TypeScript conventions and best practices
Files:
packages/kit/src/template.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
⏰ 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). (3)
- GitHub Check: build
- GitHub Check: codeql (javascript-typescript)
- GitHub Check: code
🔇 Additional comments (1)
packages/kit/src/template.ts (1)
81-96: Good fix: mutations now persist on the shared payloadSwitching from param destructuring to mutating the payload solves the lost‑push issue and aligns with the linked objectives. LGTM.
Fixes issue where nodeReferences, sharedReferences, and references arrays could be undefined when destructured in prepare:types and nitro:prepare:types hooks, causing 'Cannot read properties of undefined (reading "push")' errors during package installation.
This ensures backward compatibility by providing empty arrays as defaults when the hook payload doesn't contain these properties.
🔗 Linked issue
Resolves #33238
📚 Description
This PR fixes a critical issue where running
bun installornpm installfails due to undefined reference arrays in theprepare:typesandnitro:prepare:typeshooks.Problem:
nodeReferences,sharedReferences, andreferencesfrom hook payloadsSolution:
= []) when destructuring these properties in hook payloadsImpact:
This fix resolves installation failures and maintains full backward compatibility while preventing runtime errors during the build process.