Backtestsvuerun-20261013-093701#11910

Issue #11910 Merged fix PR #11959 Run 13 Oct 2026 · run-20261013-093701 vuejs/core

Transition should sniff for teleport in custom components

Better

Our patch was judged better than the merged fix.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Both patches fix the core bug: a component whose root is a Teleport now gets its transition hooks forwarded to the teleported element instead of the Teleport vnode. Both include e2e tests showing the enter and leave classes applied to the teleported node.

Patch A redirects the hooks in two places (`renderComponentRoot` and the component branch of `setTransitionHooks`) using the exported `getInnerChild`. This works for the basic case. However, it blindly moves the hooks onto whatever non-comment child it finds. If the Teleport content is a Fragment or other non-transitionable node, the hooks land on a node that never calls `afterLeave`. That can stall `mode: "out-in"`. Its unit tests are fairly thin: a KeepAlive case, an empty-Teleport case, and a hook-update case. None of them directly checks enter/leave callbacks on teleported content.

Patch B makes Teleport transparent inside `setTransitionHooks` itself, so every path benefits, including HOC nesting and the update path. It forwards the hooks to the content only when that content can carry them (an element, a component, or a comment placeholder for v-if switches). Otherwise it keeps the hooks on the Teleport, which preserves `afterLeave` for out-in. It also guards against unnormalized children. The dev warning is made Teleport-aware, so it still fires for multi-root or non-element content but not for valid single-element content.

Patch B's tests are substantially stronger. They cover full leave/enter cycles with element assertions for a direct Teleport root, an HOC wrapper, component content, and out-in mode. They also cover warning behavior, the fallback of keeping hooks on the Teleport, and unnormalized children.

Patch B is more robust at the edges and better tested, with no added risk to the core fix.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

10m 4s

Wall-clock time in the container

Full test suite

No new failures

1,751 passed · 1 skipped · 1,752 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

250vs 160 merged

Changed lines, ours vs merged

Vue version

3.5.4

Link to minimal reproduction

https://play.vuejs.org/#eNqNVE1v2zAM/SuadugGNHaG7pS5xT5QYNthG9YcfVFsOlEjS4JEOwmC/PdRUpw6RVrsZIt87+mRErXnX6zN+g74jBe+ctIi84CdvSu1bK1xyPbMQcMOrHGmZVcEvTqlvpnWHuNZHhZB6epTqUtdGe1JamU27DYIvGuE8vC+1EWetqENaIHQWiUQaMVYsegQjWafKyWr9W3Jj/Q34Vvyuwf65N9lDUWekIk1d0J7iZKYWrRAvEbUQPiQpXx02U9kc1QsOcsTM3+iRjv/ITYHBbF2NJRbmHpHcmfiRyRha9kzWQcJYyhe5BQYdPJB6JKTIh/1hZYedyr8ZsHLBDSCm4S2Xw8hBaKHCRq2D2rGikribsamdBSHoDAmonlGiwd4TvxwiSgqlD08I6dgouOphhkTSrFpduMZCA+D2ltqRIIuRLVeOtPpesYWqgsIxjayxhVtPp3abQysQC5XOI4sjKvBUcRumTdK1sQmqbQBXa3YKH7N0dMFbOQye/RG092Om5a8oqsgFbjfNrj0JZ8lOyFHjs3mZ4yh60KdKV6toFpfiD/6bYiV/I8DD66nS3LKoXBLwJS+f/gFW/o/JVtTd4rQryT/AhXXBY8J9pUaRbZHuOj2RxxDqZdzf79FoOYfiwpGA/IQ8SWnsQxT8FLpT3Zvso+RR/2kLg4jfeFxGD0Pp5EYvxHxEXht1i8N0jAcLw7O2dicTQk//AP1sJ3y

Steps to reproduce

Click the button

What is expected?

Both should transition in

What is actually happening?

One transitions correctly, the other throws a warning and blinks into existance

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD Ryzen 7 PRO 6850HS with Radeon Graphics
    Memory: 11.86 GB / 15.28 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.2.0 - ~/.nvm/versions/node/v22.2.0/bin/node
    Yarn: 3.2.2 - ~/.nvm/versions/node/v22.2.0/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v22.2.0/bin/npm
    pnpm: 7.25.0 - ~/.nvm/versions/node/v22.2.0/bin/pnpm
    bun: 1.1.8 - ~/.bun/bin/bun
  Browsers:
    Chrome: 126.0.6478.55

Any additional comments?

This is a follow up from

  • #5836

My Intention in #5836 was, that a user should be able to do this:

<Transition>
  <CustomComp />
</Transition>

<!-- Custom Comp -->
<Teleport>
  <div></div>
</Teleport>

However, the fix for #5836 only allows:

<Transition>
  <Teleport>
    <div></div>
  </Teleport>
</Transition>

For me as a user those 2 should feel equivalent.
The way it is now is not really useful. If you are not gonna use a custom component inside transition, you could just easily swap teleport and transition around (which already worked before the fix):

<teleport>
  <transition>
    <div></div>
  </transition>
</teleport>

But the whole point of #5836 was to allow to transition any component that teleports internally.
And since nesting a custom component into a transition works already, teleport should just be transparent in this case

Usecase:

  • modals <transition><Modal /></transition>
  • popovers
  • ...

The two patches

Our patch+249 −1
packages/runtime-core/__tests__/components/BaseTransition.spec.tsindex c541d5fc4..790893901 100644@@ -1,7 +1,9 @@ import {   BaseTransition,   type BaseTransitionProps,+  Fragment,   KeepAlive,+  Teleport,   type TestElement,   type VNodeProps,   h,@@ -11,6 +13,7 @@ import {   render,   serialize,   serializeInner,+  setTransitionHooks, } from '@vue/runtime-test'  function mount(@@ -1293,4 +1296,130 @@ describe('BaseTransition', () => {     await runTestWithKeepAlive(testOutIn)     __DEV__ = true   })++  // #11887 a custom component that renders a Teleport as root should be+  // transitioned just like a Teleport placed directly inside <Transition>+  describe('w/ Teleport inside component', () => {+    async function testTeleportToggle(+      makeChild: (target: TestElement, msg: string) => any,+      mode?: BaseTransitionProps['mode'],+    ) {+      const target = nodeOps.createElement('div')+      const toggle = ref(true)+      const { props, cbs } = mockProps({ mode })+      const { root } = mount(props, () =>+        toggle.value ? makeChild(target, 'foo') : null,+      )+      expect(serializeInner(target)).toBe(`<div>foo</div>`)+      expect(serializeInner(root)).toBe(+        `<!--teleport start--><!--teleport end-->`,+      )++      // leave+      toggle.value = false+      await nextTick()+      expect(props.onBeforeLeave).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onBeforeLeave, `<div>foo</div>`)+      expect(props.onLeave).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onLeave, `<div>foo</div>`)+      // element stays until leave is done+      expect(serializeInner(target)).toBe(`<div>foo</div>`)+      cbs.doneLeave[`<div>foo</div>`]()+      expect(serializeInner(target)).toBe(``)+      expect(props.onAfterLeave).toHaveBeenCalledTimes(1)++      // enter+      toggle.value = true+      await nextTick()+      expect(serializeInner(target)).toBe(`<div>foo</div>`)+      expect(props.onBeforeEnter).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onBeforeEnter, `<div>foo</div>`)+      expect(props.onEnter).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onEnter, `<div>foo</div>`)+      cbs.doneEnter[`<div>foo</div>`]()+      expect(props.onAfterEnter).toHaveBeenCalledTimes(1)++      expect(+        `renders non-element root node that cannot be animated`,+      ).not.toHaveBeenWarned()+    }++    test('teleport as component root', async () => {+      const Comp = (p: { to: TestElement; msg: string }) =>+        h(Teleport, { to: p.to }, [h('div', p.msg)])+      await testTeleportToggle((to, msg) => h(Comp, { to, msg }))+    })++    test('teleport as root of nested component (HOC)', async () => {+      const Inner = (p: { to: TestElement; msg: string }) =>+        h(Teleport, { to: p.to }, [h('div', p.msg)])+      const Outer = (p: { to: TestElement; msg: string }) => h(Inner, p)+      await testTeleportToggle((to, msg) => h(Outer, { to, msg }))+    })++    test('teleport content is a component', async () => {+      const Content = (p: { msg: string }) => h('div', p.msg)+      const Comp = (p: { to: TestElement; msg: string }) =>+        h(Teleport, { to: p.to }, [h(Content, { msg: p.msg })])+      await testTeleportToggle((to, msg) => h(Comp, { to, msg }))+    })++    test('teleport as component root w/ mode: "out-in"', async () => {+      const Comp = (p: { to: TestElement; msg: string }) =>+        h(Teleport, { to: p.to }, [h('div', p.msg)])+      await testTeleportToggle((to, msg) => h(Comp, { to, msg }), 'out-in')+    })++    test('should still warn when teleport content is not a single element', () => {+      const target = nodeOps.createElement('div')+      const Comp = () => h(Teleport, { to: target }, [h('div'), h('span')])+      const { props } = mockProps()+      mount(props, () => h(Comp))+      expect(+        `renders non-element root node that cannot be animated`,+      ).toHaveBeenWarned()+      expect(+        `<transition> can only be used on a single element or component`,+      ).toHaveBeenWarned()+    })++    test('should keep hooks on teleport when its content cannot carry them', () => {+      const hooks = { afterLeave: vi.fn() } as any+      // a fragment is removed without calling afterLeave, so the hooks must+      // stay on the teleport for mode: "out-in" to be able to proceed+      const fragmentChild = h(Fragment, [h('div')])+      const withFragment = h(Teleport, { to: 'body' }, [fragmentChild])+      setTransitionHooks(withFragment, hooks)+      expect(withFragment.transition).toBe(hooks)+      expect(fragmentChild.transition).toBe(null)++      const empty = h(Teleport, { to: 'body' }, [])+      setTransitionHooks(empty, hooks)+      expect(empty.transition).toBe(hooks)++      const elChild = h('div')+      const withElement = h(Teleport, { to: 'body' }, [elChild])+      setTransitionHooks(withElement, hooks)+      expect(withElement.transition).toBe(null)+      expect(elChild.transition).toBe(hooks)+    })++    test('should not throw on unnormalized teleport children', async () => {+      const target = nodeOps.createElement('div')+      const toggle = ref(true)+      const Comp = () => h(Teleport, { to: target }, [null, h('div', 'foo')])+      const { props, cbs } = mockProps()+      mount(props, () => (toggle.value ? h(Comp) : null))+      expect(serializeInner(target)).toBe(`<!---->` + `<div>foo</div>`)++      toggle.value = false+      await nextTick()+      cbs.doneLeave[`<div>foo</div>`]?.()+      expect(serializeInner(target)).toBe(``)+      expect(props.onAfterLeave).toHaveBeenCalledTimes(1)+      expect(+        `renders non-element root node that cannot be animated`,+      ).toHaveBeenWarned()+    })+  }) })packages/runtime-core/src/componentRenderUtils.tsindex 0b46130c0..4a9498458 100644@@ -18,6 +18,7 @@ import { ErrorCodes, handleError } from './errorHandling' import {   PatchFlags,   ShapeFlags,+  isArray,   isModelListener,   isObject,   isOn,@@ -255,7 +256,7 @@ export function renderComponentRoot(   }   // inherit transition data   if (vnode.transition) {-    if (__DEV__ && !isElementRoot(root)) {+    if (__DEV__ && !isTransitionableRoot(root)) {       warn(         `Component inside <Transition> renders non-element root node ` +           `that cannot be animated.`,@@ -368,6 +369,20 @@ const isElementRoot = (vnode: VNode) => {   ) } +const isTransitionableRoot = (vnode: VNode): boolean => {+  if (vnode.shapeFlag & ShapeFlags.TELEPORT) {+    // transition hooks are forwarded to the teleported content+    const children = vnode.children+    if (!isArray(children) || !children.every(isVNode)) return false+    const content = (children as VNode[]).filter(c => c.type !== Comment)+    // comment-only content is a potential v-if branch switch+    return content.length === 0+      ? children.length > 0+      : content.length === 1 && !!isElementRoot(content[0])+  }+  return !!isElementRoot(vnode)+}+ export function shouldUpdateComponent(   prevVNode: VNode,   nextVNode: VNode,packages/runtime-core/src/components/BaseTransition.tsindex 4a9d5098e..9be243d19 100644@@ -12,6 +12,7 @@ import {   cloneVNode,   createCommentVNode,   isSameVNodeType,+  isVNode, } from '../vnode' import { warn } from '../warning' import { isKeepAlive } from './KeepAlive'@@ -542,6 +543,26 @@ export function setTransitionHooks(vnode: VNode, hooks: TransitionHooks): void {   } else if (__FEATURE_SUSPENSE__ && vnode.shapeFlag & ShapeFlags.SUSPENSE) {     vnode.ssContent!.transition = hooks.clone(vnode.ssContent!)     vnode.ssFallback!.transition = hooks.clone(vnode.ssFallback!)+  } else if (vnode.shapeFlag & ShapeFlags.TELEPORT) {+    // a teleport is transparent to transitions: apply the hooks to its+    // content, e.g. when it is the root of a component inside <Transition>+    const children = vnode.children+    const child =+      isArray(children) &&+      children.length &&+      children.every(isVNode) &&+      findNonCommentChild(children as VNode[])+    if (+      child &&+      (child.shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.COMPONENT) ||+        child.type === Comment)+    ) {+      setTransitionHooks(child, hooks)+    } else {+      // content that cannot carry the hooks (e.g. a fragment): keep them on+      // the teleport so that removing it still calls afterLeave (out-in)+      vnode.transition = hooks+    }   } else {     vnode.transition = hooks   }packages/vue/__tests__/e2e/Transition.spec.tsindex 17519e832..1396d99d1 100644@@ -2784,6 +2784,89 @@ describe('e2e: Transition', () => {     )   }) +  describe('transition with Teleport inside component', () => {+    test(+      'apply transition to teleport child of custom component',+      async () => {+        await page().evaluate(() => {+          const { createApp, ref, h, Teleport } = (window as any).Vue+          createApp({+            template: `+            <div id="target"></div>+            <div id="container">+              <transition>+                <Comp v-if="toggle" />+              </transition>+            </div>+            <button id="toggleBtn" @click="click">button</button>+          `,+            components: {+              Comp: {+                setup() {+                  return () =>+                    h(Teleport, { to: '#target' }, [+                      h('div', { class: 'test' }, 'content'),+                    ])+                },+              },+            },+            setup: () => {+              const toggle = ref(false)+              const click = () => (toggle.value = !toggle.value)+              return { toggle, click }+            },+          }).mount('#app')+        })++        expect(await html('#target')).toBe('')+        expect(await html('#container')).toBe('<!--v-if-->')++        const classWhenTransitionStart = () =>+          page().evaluate(() => {+            ;(document.querySelector('#toggleBtn') as any)!.click()+            return Promise.resolve().then(() => {+              // find the class of teleported node+              return document+                .querySelector('#target div')!+                .className.split(/\s+/g)+            })+          })++        // enter+        expect(await classWhenTransitionStart()).toStrictEqual([+          'test',+          'v-enter-from',+          'v-enter-active',+        ])+        await nextFrame()+        expect(await classList('.test')).toStrictEqual([+          'test',+          'v-enter-active',+          'v-enter-to',+        ])+        await transitionFinish()+        expect(await html('#target')).toBe('<div class="test">content</div>')++        // leave+        expect(await classWhenTransitionStart()).toStrictEqual([+          'test',+          'v-leave-from',+          'v-leave-active',+        ])+        await nextFrame()+        expect(await classList('.test')).toStrictEqual([+          'test',+          'v-leave-active',+          'v-leave-to',+        ])+        await transitionFinish()+        expect(await html('#target')).toBe('')+        expect(await html('#container')).toBe('<!--v-if-->')+      },+      E2E_TIMEOUT,+    )+  })+   describe('transition with v-show', () => {     test(       'named transition with v-show', 
Merged fix · PR #11959+155 −5
packages/runtime-core/__tests__/components/BaseTransition.spec.tsindex c541d5fc4..65abcc6ff 100644@@ -2,6 +2,7 @@ import {   BaseTransition,   type BaseTransitionProps,   KeepAlive,+  Teleport,   type TestElement,   type VNodeProps,   h,@@ -1293,4 +1294,66 @@ describe('BaseTransition', () => {     await runTestWithKeepAlive(testOutIn)     __DEV__ = true   })++  test('should preserve transition for component with KeepAlive root', async () => {+    const root = nodeOps.createElement('div')+    const show = ref(false)+    const onBeforeEnter = vi.fn()+    const Child = { render: () => h('div', 'content') }+    const Comp = {+      render: () => h(KeepAlive, null, { default: () => h(Child) }),+    }+    const App = () =>+      h(BaseTransition, { onBeforeEnter }, () => (show.value ? h(Comp) : null))++    render(h(App), root)++    show.value = true+    await nextTick()+    expect(serializeInner(root)).toBe('<div>content</div>')+    expect(onBeforeEnter).toHaveBeenCalledTimes(1)+  })++  test('should not error on component with empty Teleport root', () => {+    const root = nodeOps.createElement('div')+    const target = nodeOps.createElement('div')+    const Comp = () => h(Teleport, { to: target }, [])++    expect(() =>+      render(+        h(BaseTransition, null, () => h(Comp)),+        root,+      ),+    ).not.toThrow()+    expect(serializeInner(root)).toBe(+      '<!--teleport start--><!--teleport end-->',+    )+    expect(serializeInner(target)).toBe('')+    expect(+      'Component inside <Transition> renders non-element root node',+    ).toHaveBeenWarned()+  })++  test('should update transition hooks for component with Teleport root', async () => {+    const root = nodeOps.createElement('div')+    const target = nodeOps.createElement('div')+    const show = ref(true)+    const firstBeforeLeave = vi.fn()+    const nextBeforeLeave = vi.fn()+    const beforeLeave = ref(firstBeforeLeave)+    const Comp = () => h(Teleport, { to: target }, h('div', 'content'))+    const App = () =>+      h(BaseTransition, { onBeforeLeave: beforeLeave.value }, () =>+        show.value ? h(Comp) : null,+      )++    render(h(App), root)++    beforeLeave.value = nextBeforeLeave+    show.value = false+    await nextTick()++    expect(firstBeforeLeave).not.toHaveBeenCalled()+    expect(nextBeforeLeave).toHaveBeenCalledTimes(1)+  }) })packages/runtime-core/src/componentRenderUtils.tsindex 0b46130c0..be58e5b0a 100644@@ -34,7 +34,8 @@ import {   warnDeprecation, } from './compat/compatConfig' import { shallowReadonly } from '@vue/reactivity'-import { setTransitionHooks } from './components/BaseTransition'+import { getInnerChild, setTransitionHooks } from './components/BaseTransition'+import { isTeleport } from './components/Teleport'  /**  * dev only flag to track whether $attrs was used during render.@@ -255,13 +256,14 @@ export function renderComponentRoot(   }   // inherit transition data   if (vnode.transition) {-    if (__DEV__ && !isElementRoot(root)) {+    const child = isTeleport(root.type) ? getInnerChild(root) || root : root+    if (__DEV__ && !isElementRoot(child)) {       warn(         `Component inside <Transition> renders non-element root node ` +           `that cannot be animated.`,       )     }-    setTransitionHooks(root, vnode.transition)+    setTransitionHooks(child, vnode.transition)   }    if (__DEV__ && setRoot) {packages/runtime-core/src/components/BaseTransition.tsindex 4a9d5098e..a8cfe8b71 100644@@ -506,7 +506,7 @@ function emptyPlaceholder(vnode: VNode): VNode | undefined {   } } -function getInnerChild(vnode: VNode): VNode | undefined {+export function getInnerChild(vnode: VNode): VNode | undefined {   if (!isKeepAlive(vnode)) {     if (isTeleport(vnode.type) && vnode.children) {       return findNonCommentChild(vnode.children as VNode[])@@ -538,7 +538,11 @@ function getInnerChild(vnode: VNode): VNode | undefined { export function setTransitionHooks(vnode: VNode, hooks: TransitionHooks): void {   if (vnode.shapeFlag & ShapeFlags.COMPONENT && vnode.component) {     vnode.transition = hooks-    setTransitionHooks(vnode.component.subTree, hooks)+    const subTree = vnode.component.subTree+    setTransitionHooks(+      isTeleport(subTree.type) ? getInnerChild(subTree) || subTree : subTree,+      hooks,+    )   } else if (__FEATURE_SUSPENSE__ && vnode.shapeFlag & ShapeFlags.SUSPENSE) {     vnode.ssContent!.transition = hooks.clone(vnode.ssContent!)     vnode.ssFallback!.transition = hooks.clone(vnode.ssFallback!)packages/vue/__tests__/e2e/Transition.spec.tsindex 17519e832..025cc7c00 100644@@ -2782,6 +2782,87 @@ describe('e2e: Transition', () => {       },       E2E_TIMEOUT,     )++    // #11910+    test(+      'apply transition to teleport component child',+      async () => {+        await page().evaluate(() => {+          const { createApp, ref } = (window as any).Vue+          createApp({+            template: `+            <div id="target"></div>+            <div id="container">+              <transition>+                  <Comp v-if="toggle"></Comp>+              </transition>+            </div>+            <button id="toggleBtn" @click="click">button</button>+          `,+            components: {+              Comp: {+                template: `+                    <Teleport to="#target">+                      <div class="test">content</div>+                    </Teleport>+                  `,+              },+            },+            setup: () => {+              const toggle = ref(false)+              const click = () => (toggle.value = !toggle.value)+              return { toggle, click }+            },+          }).mount('#app')+        })++        expect(await html('#target')).toBe('')+        expect(await html('#container')).toBe('<!--v-if-->')++        const classWhenTransitionStart = () =>+          page().evaluate(() => {+            ;(document.querySelector('#toggleBtn') as any)!.click()+            return Promise.resolve().then(() => {+              // find the class of teleported node+              return document+                .querySelector('#target div')!+                .className.split(/\s+/g)+            })+          })++        // enter+        expect(await classWhenTransitionStart()).toStrictEqual([+          'test',+          'v-enter-from',+          'v-enter-active',+        ])+        await nextFrame()+        expect(await classList('.test')).toStrictEqual([+          'test',+          'v-enter-active',+          'v-enter-to',+        ])+        await transitionFinish()+        expect(await html('#target')).toBe('<div class="test">content</div>')++        // leave+        expect(await classWhenTransitionStart()).toStrictEqual([+          'test',+          'v-leave-from',+          'v-leave-active',+        ])+        await nextFrame()+        expect(await classList('.test')).toStrictEqual([+          'test',+          'v-leave-active',+          'v-leave-to',+        ])+        await transitionFinish()+        expect(await html('#target')).toBe('')+        expect(await html('#container')).toBe('<!--v-if-->')+      },+      E2E_TIMEOUT,+    )   })    describe('transition with v-show', () => {