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: shouldn't throw error on hydration Teleport mismatch #1271

Merged
merged 3 commits into from
Jun 12, 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
16 changes: 16 additions & 0 deletions packages/runtime-core/__tests__/hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const triggerEvent = (type: string, el: Element) => {
describe('SSR hydration', () => {
mockWarn()

beforeEach(() => {
document.body.innerHTML = ''
})

test('text', async () => {
const msg = ref('foo')
const { vnode, container } = mountWithHydration('foo', () => msg.value)
Expand Down Expand Up @@ -686,5 +690,17 @@ describe('SSR hydration', () => {
// excessive children removal
expect(`Hydration children mismatch`).toHaveBeenWarned()
})

test('Teleport target has empty children', () => {
const teleportContainer = document.createElement('div')
teleportContainer.id = 'teleport'
document.body.appendChild(teleportContainer)

mountWithHydration('<!--teleport start--><!--teleport end-->', () =>
h(Teleport, { to: '#teleport' }, [h('span', 'value')])
)
expect(teleportContainer.innerHTML).toBe(`<span>value</span>`)
expect(`Hydration children mismatch`).toHaveBeenWarned()
})
})
})
5 changes: 2 additions & 3 deletions packages/runtime-core/src/components/Teleport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,8 @@ function hydrateTeleport(
optimized
)
}
;(target as TeleportTargetElement)._lpa = nextSibling(
vnode.targetAnchor as Node
)
;(target as TeleportTargetElement)._lpa =
vnode.targetAnchor && nextSibling(vnode.targetAnchor as Node)
}
}
return vnode.anchor && nextSibling(vnode.anchor as Node)
Expand Down