Skip to content

Commit 9c44527

Browse files
committed
introduce castrateObject
+ get rid of `__v_skip`, coming from vue@3.5.28 Signed-off-by: 🕷️ <3756473+zendive@users.noreply.github.com>
1 parent 74eb12f commit 9c44527

3 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/api/clone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export function stripDeepObjectPrototype<T>(unk: T): T {
330330

331331
// @ts-expect-error in 2026, typescript doesn't know yet
332332
for (const value of unk) {
333-
rv.push(stripDeepObjectPrototype(value));
333+
rv.push(stripDeepObjectPrototype(value)); // recursion
334334
}
335335

336336
return <T> rv;
@@ -341,7 +341,7 @@ export function stripDeepObjectPrototype<T>(unk: T): T {
341341
const obj = <ISerializableObject> unk;
342342

343343
for (const key of Reflect.ownKeys(obj)) {
344-
rv[key] = stripDeepObjectPrototype(obj[key]);
344+
rv[key] = stripDeepObjectPrototype(obj[key]); // recursion
345345
}
346346

347347
return <T> rv;

src/api/diffApi.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { hasValue } from './toolkit.ts';
2-
import { type ISerializableObject, stripDeepObjectPrototype } from './clone.ts';
2+
import { type ISerializableObject } from './clone.ts';
33
import { create, type Delta } from 'jsondiffpatch/with-text-diffs';
44
import { format as formatHtml } from 'jsondiffpatch/formatters/html';
55
import { format as formatRFC6902 } from 'jsondiffpatch/formatters/jsonpatch';
@@ -54,10 +54,7 @@ export function buildDeltaElement(
5454
let html: string | undefined;
5555

5656
try {
57-
html = formatHtml(
58-
stripDeepObjectPrototype(delta),
59-
stripDeepObjectPrototype(left),
60-
);
57+
html = formatHtml(delta, left);
6158
html = DOMPurify.sanitize(html || '');
6259
} catch (e) {
6360
console.error('buildDeltaElement', e);

src/stores/compare.store.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ function defaultCompareState(): ICompareState {
2121
};
2222
}
2323

24+
function castrateObject<T>(that: T): T {
25+
if (that !== null && typeof that === 'object') {
26+
return markRaw(Object.freeze(stripDeepObjectPrototype(that)));
27+
}
28+
29+
return that;
30+
}
31+
2432
export const useCompareStore = defineStore('compareStore', {
2533
state: () => ({
2634
initialized: false,
@@ -38,20 +46,15 @@ export const useCompareStore = defineStore('compareStore', {
3846
},
3947

4048
deltaObj(): Delta {
41-
return diff(
42-
stripDeepObjectPrototype(this.compare.left),
43-
stripDeepObjectPrototype(this.compare.right),
44-
);
49+
return castrateObject(diff(this.compare.left, this.compare.right));
4550
},
4651
},
4752

4853
actions: {
4954
assign({ left, right, timestamp }: ICompareState) {
5055
this.compare = {
51-
left: left !== null && typeof left === 'object' ? markRaw(left) : left,
52-
right: right !== null && typeof right === 'object'
53-
? markRaw(right)
54-
: right,
56+
left: castrateObject(left),
57+
right: castrateObject(right),
5558
timestamp: timestamp || Date.now(),
5659
};
5760
},

0 commit comments

Comments
 (0)