Skip to content

Commit 094f4b3

Browse files
authored
Merge pull request #164 from opentiny/fix-clone-proxy-data
fix(core): fix structuredClone error when use ref json and isJsonComplete is false
2 parents a427a80 + c7e9d55 commit 094f4b3

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

packages/core/src/delta-patcher/delta-patcher.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ export interface IPatchOptions {
1212
requiredCompleteFieldSelectors?: string[];
1313
}
1414

15+
function deepClone(obj: any): any {
16+
if (!obj || typeof obj !== 'object') {
17+
return obj;
18+
}
19+
let cloneData
20+
try {
21+
cloneData = structuredClone(obj);
22+
} catch (error) {
23+
cloneData = JSON.parse(JSON.stringify(obj));
24+
}
25+
return cloneData;
26+
}
27+
1528
export class DeltaPatcher {
1629
protected diffPatcher: jsonDiffPatch.DiffPatcher;
1730
protected options: IPatchOptions;
@@ -94,7 +107,7 @@ export class DeltaPatcher {
94107
};
95108

96109
if (isMatch) {
97-
const cloneDelta = structuredClone(delta);
110+
const cloneDelta = deepClone(delta);
98111
const deltaPath = this.getActualMatchPath(lastKey, matchPath, deltaIndex ?? -1);
99112
const { parent, selfKey } = deltaPath.match(/((?<parent>.*)\.)?(?<selfKey>.*?)$/)?.groups || {};
100113

0 commit comments

Comments
 (0)