Skip to content

Commit 5c9ade5

Browse files
baiwusanyu-cyyx990803
authored andcommitted
fix(runtime-core): fix error when using cssvars with disabled teleport (#7341)
close #7342
1 parent ac68f22 commit 5c9ade5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/runtime-core/src/components/Teleport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ function updateCssVars(vnode: VNode) {
414414
const ctx = vnode.ctx
415415
if (ctx && ctx.ut) {
416416
let node = (vnode.children as VNode[])[0].el!
417-
while (node !== vnode.targetAnchor) {
417+
while (node && node !== vnode.targetAnchor) {
418418
if (node.nodeType === 1) node.setAttribute('data-v-owner', ctx.uid)
419419
node = node.nextSibling
420420
}

packages/runtime-dom/__tests__/helpers/useCssVars.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,22 @@ describe('useCssVars', () => {
275275
expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('red')
276276
}
277277
})
278+
279+
test('with teleport(disabled)', async () => {
280+
document.body.innerHTML = ''
281+
const state = reactive({ color: 'red' })
282+
const root = document.createElement('div')
283+
const target = document.body
284+
285+
const App = {
286+
setup() {
287+
useCssVars(() => state)
288+
return () => [h(Teleport, { to: target, disabled: true }, [h('div')])]
289+
}
290+
}
291+
292+
expect(() => render(h(App), root)).not.toThrow(TypeError)
293+
await nextTick()
294+
expect(target.children.length).toBe(0)
295+
})
278296
})

0 commit comments

Comments
 (0)