-
Notifications
You must be signed in to change notification settings - Fork 2.7k
cloneDeep
: use structuredClone
in platforms where that's possible
#12491
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: release-4.0
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 8662e58 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
cloneDeep
: use structuredClone
in platform where that's possiblecloneDeep
: use structuredClone
in platforms where that's possible
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.
Pull Request Overview
This PR updates the cloneDeep implementation to use the native structuredClone API where available while preserving compatibility with React Native by maintaining a dedicated implementation. The key changes include:
- Refactoring cloneDeep in common/cloneDeep.ts to use structuredClone with a fallback.
- Introducing a new cloneDeep implementation for React Native in common/cloneDeep.react-native.ts.
- Export updates in index.react-native.ts and a corresponding changeset update.
Reviewed Changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
src/utilities/index.react-native.ts | Updates module exports for React Native by referencing the new file. |
src/utilities/common/cloneDeep.ts | Refactors cloneDeep to use structuredClone with a fallback. |
src/utilities/common/cloneDeep.react-native.ts | Provides a React Native version of cloneDeep (duplicate helper definition present). |
.changeset/nice-icons-approve.md | Documents the changeset for the cloneDeep refactor. |
Files not reviewed (1)
- package.json: Language not supported
Comments suppressed due to low confidence (1)
src/utilities/common/cloneDeep.react-native.ts:41
- Duplicate definition of cloneDeepHelper detected; remove the redundant implementation to prevent confusion and potential maintenance issues.
function cloneDeepHelper<T>(val: T, seen?: Map<any, any>): T {
} catch { | ||
return value; | ||
} |
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.
The fallback in cloneDeep returns the original value instead of performing a deep clone, which may result in unintended shared references; consider implementing a recursive deep cloning fallback for environments without structuredClone support.
} catch { | |
return value; | |
} | |
} catch { | |
return deepClone(value); | |
} | |
} | |
function deepClone<T>(value: T): T { | |
if (value === null || typeof value !== 'object') { | |
return value; | |
} | |
if (Array.isArray(value)) { | |
const arrCopy = [] as any[]; | |
for (const item of value) { | |
arrCopy.push(deepClone(item)); | |
} | |
return arrCopy as any; | |
} | |
const objCopy = {} as { [key: string]: any }; | |
for (const key in value) { | |
if (Object.prototype.hasOwnProperty.call(value, key)) { | |
objCopy[key] = deepClone((value as { [key: string]: any })[key]); | |
} | |
} | |
return objCopy as T; |
Copilot uses AI. Check for mistakes.
|
commit: |
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
size-limit report 📦
|
No description provided.