Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Teleport): fallback to non-optimized mode when HRM performing updates #3311

Merged
merged 2 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions packages/runtime-core/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,65 @@ describe('hot module replacement', () => {
rerender(last.__hmrId!, compileToFunction(`<Parent class="test"/>`))
expect(serializeInner(root)).toBe(`<div class="test">child</div>`)
})

// #3302
test('rerender with Teleport', () => {
const root = nodeOps.createElement('div')
const target = nodeOps.createElement('div')
const parentId = 'parent-teleport'

const Child: ComponentOptions = {
data() {
return {
// style is used to ensure that the div tag will be tracked by Teleport
style: {},
target
}
},
render: compileToFunction(`
<teleport :to="target">
<div :style="style">
<slot/>
</div>
</teleport>
`)
}

const Parent: ComponentOptions = {
__hmrId: parentId,
components: { Child },
render: compileToFunction(`
<Child>
<template #default>
<div>1</div>
</template>
</Child>
`)
}
createRecord(parentId, Parent)

render(h(Parent), root)
expect(serializeInner(root)).toBe(
`<!--teleport start--><!--teleport end-->`
)
expect(serializeInner(target)).toBe(`<div style={}><div>1</div></div>`)

rerender(
parentId,
compileToFunction(`
<Child>
<template #default>
<div>1</div>
<div>2</div>
</template>
</Child>
`)
)
expect(serializeInner(root)).toBe(
`<!--teleport start--><!--teleport end-->`
)
expect(serializeInner(target)).toBe(
`<div style={}><div>1</div><div>2</div></div>`
)
})
})
8 changes: 8 additions & 0 deletions packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { VNode, VNodeArrayChildren, VNodeProps } from '../vnode'
import { isString, ShapeFlags } from '@vue/shared'
import { warn } from '../warning'
import { isHmrUpdating } from '../hmr'

export type TeleportVNode = VNode<RendererNode, RendererElement, TeleportProps>

Expand Down Expand Up @@ -84,6 +85,13 @@ export const TeleportImpl = {
const disabled = isTeleportDisabled(n2.props)
const { shapeFlag, children } = n2

// #3302
// HMR updated, force full diff
if (__DEV__ && isHmrUpdating) {
optimized = false
n2.dynamicChildren = null
}

if (n1 == null) {
// insert anchors in the main view
const placeholder = (n2.el = __DEV__
Expand Down