8000 fix: handle circular references in HMR check · unplugin/unplugin-vue@df28f79 · GitHub
[go: up one dir, main page]

Skip to content

Commit df28f79

Browse files
committed
fix: handle circular references in HMR check
ref: vitejs/vite-plugin-vue@eddcfa8
1 parent aa41e9d commit df28f79

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/core/handleHotUpdate.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,25 @@ export function isOnlyTemplateChanged(
197197
)
198198
}
199199

200-
function deepEqual(obj1: any, obj2: any, excludeProps: string[] = []): boolean {
200+
function deepEqual(
201+
obj1: any,
202+
obj2: any,
203+
excludeProps: string[] = [],
204+
deepParentsOfObj1: any[] = [],
205+
): boolean {
201206
// Check if both objects are of the same type
202207
if (typeof obj1 !== typeof obj2) {
203208
return false
204209
}
205210

206211
// Check if both objects are primitive types or null
207-
if (obj1 == null || obj2 == null || typeof obj1 !== 'object') {
212+
// or circular reference
213+
if (
214+
obj1 == null ||
215+
obj2 == null ||
216+
typeof obj1 !== 'object' ||
217+
deepParentsOfObj1.includes(obj1)
218+
) {
208219
return obj1 === obj2
209220
}
210221

@@ -224,7 +235,12 @@ function deepEqual(obj1: any, obj2: any, excludeProps: string[] = []): boolean {
224235
continue
225236
}
226237

227-
if (!deepEqual(obj1[key], obj2[key], excludeProps)) {
238+
if (
239+
!deepEqual(obj1[key], obj2[key], excludeProps, [
240+
...deepParentsOfObj1,
241+
obj1,
242+
])
243+
) {
228244
return false
229245
}
230246
}

0 commit comments

Comments
 (0)
0