Skip to content

fix(config): tolerate non-cloneable values when cloning config - #1771

Open
danielroe wants to merge 1 commit into
mainfrom
fix/runtime-config-clone
Open

fix(config): tolerate non-cloneable values when cloning config#1771
danielroe wants to merge 1 commit into
mainfrom
fix/runtime-config-clone

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

npmx-dev/npmx.dev#3094
overlaps with nuxt/nuxt#35574

📚 Description

this should be a bit safer

@pkg-pr-new

pkg-pr-new Bot commented Aug 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/test-utils@1771
npm i https://pkg.pr.new/vitest-environment-nuxt@1771

commit: d70d185

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This change adds deepCopy in src/utils.ts. The function copies plain objects and arrays, tracks visited objects with WeakMap, preserves circular references, and leaves primitives and non-plain objects unchanged. The change replaces structuredClone with deepCopy in two Nuxt config copy paths in src/config.ts. Tests cover proxy copying, function and class instance reference preservation, circular references, and getVitestConfigFromNuxt output for proxied runtimeConfig.public.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description links related issues but provides only a vague statement about improving safety. Describe that config cloning now uses deepCopy to tolerate non-cloneable values and preserve relevant references.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the config cloning change and its support for non-cloneable values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/runtime-config-clone

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/utils.ts`:
- Around line 90-94: Update the deep-copy logic around the copy target to
preserve the input object's prototype by creating it with Object.create(input's
prototype). Replace the for-in iteration with Object.keys(input), recursively
copy each own property, and define properties on the target so an own __proto__
key remains data rather than changing the prototype.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5bf8d4d8-ceda-416f-aa61-9b0dbfe8ca9d

📥 Commits

Reviewing files that changed from the base of the PR and between 7951d15 and d70d185.

📒 Files selected for processing (3)
  • src/config.ts
  • src/utils.ts
  • test/unit/config.spec.ts

Comment thread src/utils.ts
Comment on lines +90 to +94
const copy: Record<string, any> = {}
seen.set(input, copy)
for (const key in input) {
copy[key] = deepCopy((input as Record<string, any>)[key], seen)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve null prototypes and own __proto__ keys.

Line 90 always creates {}. Line 93 assigns an own __proto__ key through the inherited setter. A null-prototype object therefore changes prototype, and a JSON-derived __proto__ property is not copied as data.

Create the target with Object.create(proto). Iterate own keys with Object.keys. Define each property instead of assigning it.

Proposed fix
-  const copy: Record<string, any> = {}
+  const copy: Record<string, any> = Object.create(proto)
   seen.set(input, copy)
-  for (const key in input) {
-    copy[key] = deepCopy((input as Record<string, any>)[key], seen)
+  for (const key of Object.keys(input as Record<string, any>)) {
+    Object.defineProperty(copy, key, {
+      value: deepCopy((input as Record<string, any>)[key], seen),
+      enumerable: true,
+      writable: true,
+      configurable: true,
+    })
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils.ts` around lines 90 - 94, Update the deep-copy logic around the
copy target to preserve the input object's prototype by creating it with
Object.create(input's prototype). Replace the for-in iteration with
Object.keys(input), recursively copy each own property, and define properties on
the target so an own __proto__ key remains data rather than changing the
prototype.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant