fix: avoid mutating runtimeConfig scriptOptions#638
Conversation
|
@onmax is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe pull request includes a refactoring of the script options merging logic in src/runtime/utils.ts, replacing Object.assign() with spread operator syntax, and adds a new unit test in test/unit/utils.test.ts to verify that user-provided scriptOptions remain immutable when passed to useRegistryScript. The refactoring preserves the original merge behavior while the test ensures the function does not mutate input parameters. Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Hey, thanks for this. Sorry, I missed it somehow before now 🤷 |
useRegistryScriptusesObject.assign(userOptions?.scriptOptions || {}, options.scriptOptions || {})to merge script options. SinceObject.assignmutates the first argument anduserOptions.scriptOptionsis a reference to the runtimeConfig object, registry-defined functions likeuse()get injected directly intoruntimeConfig.public.scripts.<key>.scriptOptions. When Nuxt serializes the payload, devalue throwsCannot stringify a function.Replaced
Object.assignwith object spread to create a new object instead of mutating the runtimeConfig reference.This error is present in the latest stable and in the latest beta versions
StackBlitz
CLI Reproduction
Verify fix