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(runtime-core/Teleport): handle 0 as patchFlag value. #1836

Merged
merged 4 commits into from
Aug 14, 2020
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
5 changes: 4 additions & 1 deletion packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ export const TeleportImpl = {
parentSuspense,
isSVG
)
if (n2.patchFlag > 0 && n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
// even in block tree mode we need to make sure all root-level nodes
// in the teleport inherit previous DOM references so that they can
// be moved in future patches.
if (n2.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
const oldChildren = n1.children as VNode[]
const children = n2.children as VNode[]
for (let i = 0; i < children.length; i++) {
Expand Down
39 changes: 39 additions & 0 deletions packages/vue/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,43 @@ describe('compiler + runtime integration', () => {
).toHaveBeenWarned()
document.querySelector = origin
})

// #1813
it('should not report an error when "0" as patchFlag value', async () => {
const container = document.createElement('div')
const target = document.createElement('div')
const count = ref(0)
const origin = document.querySelector
document.querySelector = jest.fn().mockReturnValue(target)

const App = {
template: `
<teleport v-if="count < 2" to="#target">
<div>
<div>{{ count }}</div>
</div>
</teleport>
`,
data() {
return {
count
}
}
}
createApp(App).mount(container)
expect(container.innerHTML).toBe(`<!--teleport start--><!--teleport end-->`)
expect(target.innerHTML).toBe(`<div><div>0</div></div>`)

count.value++
await nextTick()
expect(container.innerHTML).toBe(`<!--teleport start--><!--teleport end-->`)
expect(target.innerHTML).toBe(`<div><div>1</div></div>`)

count.value++
await nextTick()
expect(container.innerHTML).toBe(`<!--v-if-->`)
expect(target.innerHTML).toBe(``)

document.querySelector = origin
})
})