]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix error when using cssvars with disabled teleport (#7341)
author白雾三语 <32354856+baiwusanyu-c@users.noreply.github.com>
Fri, 20 Oct 2023 08:34:11 +0000 (16:34 +0800)
committerGitHub <noreply@github.com>
Fri, 20 Oct 2023 08:34:11 +0000 (16:34 +0800)
close #7342

packages/runtime-core/src/components/Teleport.ts
packages/runtime-dom/__tests__/helpers/useCssVars.spec.ts

index 19ccbc5de27a85aee019b722437fee77518aa892..67092b43288082f44c95da1bbb10a0513cbd1cb9 100644 (file)
@@ -414,7 +414,7 @@ function updateCssVars(vnode: VNode) {
   const ctx = vnode.ctx
   if (ctx && ctx.ut) {
     let node = (vnode.children as VNode[])[0].el!
-    while (node !== vnode.targetAnchor) {
+    while (node && node !== vnode.targetAnchor) {
       if (node.nodeType === 1) node.setAttribute('data-v-owner', ctx.uid)
       node = node.nextSibling
     }
index 7d24ec0f43464443dc1ae0f902c026bbdd8436bd..5792a0107b137a48118de062ca18562ac6809a91 100644 (file)
@@ -275,4 +275,22 @@ describe('useCssVars', () => {
       expect((c as HTMLElement).style.getPropertyValue(`--color`)).toBe('red')
     }
   })
+
+  test('with teleport(disabled)', async () => {
+    document.body.innerHTML = ''
+    const state = reactive({ color: 'red' })
+    const root = document.createElement('div')
+    const target = document.body
+
+    const App = {
+      setup() {
+        useCssVars(() => state)
+        return () => [h(Teleport, { to: target, disabled: true }, [h('div')])]
+      }
+    }
+
+    expect(() => render(h(App), root)).not.toThrow(TypeError)
+    await nextTick()
+    expect(target.children.length).toBe(0)
+  })
 })