Skip to content

Commit 73dd0d1

Browse files
committed
fix(hmr): fix render error in change static nodes (#6978)
1 parent 6e8b6b3 commit 73dd0d1

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

packages/runtime-core/__tests__/hmr.spec.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
2020
registerRuntimeCompiler(compileToFunction)
2121

2222
function compileToFunction(template: string) {
23-
const { code } = baseCompile(template)
23+
const { code } = baseCompile(template, { hoistStatic: true })
2424
const render = new Function('Vue', code)(
2525
runtimeTest
2626
) as InternalRenderFunction
@@ -536,4 +536,32 @@ describe('hot module replacement', () => {
536536
render(h(Foo), root)
537537
expect(serializeInner(root)).toBe('bar')
538538
})
539+
540+
test('rerender in change hoisted nodes', () => {
541+
const root = nodeOps.createElement('div')
542+
const appId = 'test-app-id'
543+
const App: ComponentOptions = {
544+
__hmrId: appId,
545+
render: compileToFunction(
546+
`<div v-for="item of 2"><div>1</div></div><p>2</p><p>3</p>`
547+
)
548+
}
549+
createRecord(appId, App)
550+
551+
render(h(App), root)
552+
expect(serializeInner(root)).toBe(
553+
`<div><div>1</div></div><div><div>1</div></div><p>2</p><p>3</p>`
554+
)
555+
556+
// move the <p>3</p> into the <div>1</div>
557+
rerender(
558+
appId,
559+
compileToFunction(
560+
`<div v-for="item of 2"><div>1<p>3</p></div></div><p>2</p>`
561+
)
562+
)
563+
expect(serializeInner(root)).toBe(
564+
`<div><div>1<p>3</p></div></div><div><div>1<p>3</p></div></div><p>2</p>`
565+
)
566+
})
539567
})

packages/runtime-core/src/vnode.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
} from './componentRenderContext'
4040
import { RendererNode, RendererElement } from './renderer'
4141
import { NULL_DYNAMIC_COMPONENT } from './helpers/resolveAssets'
42-
import { hmrDirtyComponents } from './hmr'
42+
import { hmrDirtyComponents, isHmrUpdating } from './hmr'
4343
import { convertLegacyComponent } from './compat/component'
4444
import { convertLegacyVModelProps } from './compat/componentVModel'
4545
import { defineLegacyVNodeProperties } from './compat/renderFn'
@@ -423,6 +423,12 @@ function createBaseVNode(
423423
isBlockNode = false,
424424
needFullChildrenNormalization = false
425425
) {
426+
// #6978 the children maybe a hoisted array that should be cloned
427+
// since it maybe changed during HMR
428+
if (__DEV__ && isHmrUpdating && isArray(children)) {
429+
children = [...children]
430+
}
431+
426432
const vnode = {
427433
__v_isVNode: true,
428434
__v_skip: true,

0 commit comments

Comments
 (0)