|
8 | 8 | serializeInner, |
9 | 9 | triggerEvent, |
10 | 10 | TestElement, |
11 | | - nextTick |
| 11 | + nextTick, |
| 12 | + ref |
12 | 13 | } from '@vue/runtime-test' |
13 | 14 | import * as runtimeTest from '@vue/runtime-test' |
14 | 15 | import { registerRuntimeCompiler, createApp } from '@vue/runtime-test' |
@@ -194,6 +195,53 @@ describe('hot module replacement', () => { |
194 | 195 | expect(mountSpy).toHaveBeenCalledTimes(1) |
195 | 196 | }) |
196 | 197 |
|
| 198 | + // #6930 |
| 199 | + test('reload: avoid infinite recursion', async () => { |
| 200 | + const root = nodeOps.createElement('div') |
| 201 | + const childId = 'test-child-6930' |
| 202 | + const unmountSpy = jest.fn() |
| 203 | + const mountSpy = jest.fn() |
| 204 | + |
| 205 | + const Child: ComponentOptions = { |
| 206 | + __hmrId: childId, |
| 207 | + data() { |
| 208 | + return { count: 0 } |
| 209 | + }, |
| 210 | + expose: ['count'], |
| 211 | + unmounted: unmountSpy, |
| 212 | + render: compileToFunction(`<div @click="count++">{{ count }}</div>`) |
| 213 | + } |
| 214 | + createRecord(childId, Child) |
| 215 | + |
| 216 | + const Parent: ComponentOptions = { |
| 217 | + setup() { |
| 218 | + const com = ref() |
| 219 | + const changeRef = (value: any) => { |
| 220 | + com.value = value |
| 221 | + } |
| 222 | + |
| 223 | + return () => [h(Child, { ref: changeRef }), com.value?.count] |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + render(h(Parent), root) |
| 228 | + await nextTick() |
| 229 | + expect(serializeInner(root)).toBe(`<div>0</div>0`) |
| 230 | + |
| 231 | + reload(childId, { |
| 232 | + __hmrId: childId, |
| 233 | + data() { |
| 234 | + return { count: 1 } |
| 235 | + }, |
| 236 | + mounted: mountSpy, |
| 237 | + render: compileToFunction(`<div @click="count++">{{ count }}</div>`) |
| 238 | + }) |
| 239 | + await nextTick() |
| 240 | + expect(serializeInner(root)).toBe(`<div>1</div>1`) |
| 241 | + expect(unmountSpy).toHaveBeenCalledTimes(1) |
| 242 | + expect(mountSpy).toHaveBeenCalledTimes(1) |
| 243 | + }) |
| 244 | + |
197 | 245 | // #1156 - static nodes should retain DOM element reference across updates |
198 | 246 | // when HMR is active |
199 | 247 | test('static el reference', async () => { |
|
0 commit comments