|
6 | 6 | h,
|
7 | 7 | nextTick,
|
8 | 8 | nodeOps,
|
| 9 | + ref, |
9 | 10 | render,
|
10 | 11 | serializeInner,
|
11 | 12 | triggerEvent,
|
@@ -415,6 +416,53 @@ describe('hot module replacement', () => {
|
415 | 416 | expect(mountSpy).toHaveBeenCalledTimes(1)
|
416 | 417 | })
|
417 | 418 |
|
| 419 | + // #6930 |
| 420 | + test('reload: avoid infinite recursion', async () => { |
| 421 | + const root = nodeOps.createElement('div') |
| 422 | + const childId = 'test-child-6930' |
| 423 | + const unmountSpy = vi.fn() |
| 424 | + const mountSpy = vi.fn() |
| 425 | + |
| 426 | + const Child: ComponentOptions = { |
| 427 | + __hmrId: childId, |
| 428 | + data() { |
| 429 | + return { count: 0 } |
| 430 | + }, |
| 431 | + expose: ['count'], |
| 432 | + unmounted: unmountSpy, |
| 433 | + render: compileToFunction(`<div @click="count++">{{ count }}</div>`), |
| 434 | + } |
| 435 | + createRecord(childId, Child) |
| 436 | + |
| 437 | + const Parent: ComponentOptions = { |
| 438 | + setup() { |
| 439 | + const com = ref() |
| 440 | + const changeRef = (value: any) => { |
| 441 | + com.value = value |
| 442 | + } |
| 443 | + |
| 444 | + return () => [h(Child, { ref: changeRef }), com.value?.count] |
| 445 | + }, |
| 446 | + } |
| 447 | + |
| 448 | + render(h(Parent), root) |
| 449 | + await nextTick() |
| 450 | + expect(serializeInner(root)).toBe(`<div>0</div>0`) |
| 451 | + |
| 452 | + reload(childId, { |
| 453 | + __hmrId: childId, |
| 454 | + data() { |
| 455 | + return { count: 1 } |
| 456 | + }, |
| 457 | + mounted: mountSpy, |
| 458 | + render: compileToFunction(`<div @click="count++">{{ count }}</div>`), |
| 459 | + }) |
| 460 | + await nextTick() |
| 461 | + expect(serializeInner(root)).toBe(`<div>1</div>1`) |
| 462 | + expect(unmountSpy).toHaveBeenCalledTimes(1) |
| 463 | + expect(mountSpy).toHaveBeenCalledTimes(1) |
| 464 | + }) |
| 465 | + |
418 | 466 | // #1156 - static nodes should retain DOM element reference across updates
|
419 | 467 | // when HMR is active
|
420 | 468 | test('static el reference', async () => {
|
|
0 commit comments