Backtestsvuerun-20261005-155915#11910

Issue #11910 Merged fix PR #11959 Run 5 Oct 2026 · run-20261005-155915 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 root cause the same way. When a component nested in <Transition> renders a Teleport as its root, they forward the transition hooks past the Teleport to its first non-comment child. Both handle the initial render path (renderComponentRoot) and the update path (setTransitionHooks recursing into component.subTree). Patch A does this by special-casing Teleport at both call sites with `isTeleport(...) ? getInnerChild(x) || x : x`. Patch B adds a Teleport branch inside setTransitionHooks itself, so every caller gets the behavior and the hooks are never left on the Teleport vnode. Patch B's comment notes that leaving them there would fire afterLeave too early. Patch B is also more robust at the edges. It guards with `isVNode(child)` before recursing, so un-normalized primitive children (e.g. a raw string passed via h()) are skipped. Patch A would call setTransitionHooks on a raw string and assign `.transition` to a primitive, which throws in strict-mode ESM. Patch B's dev warning uses a dedicated isTransitionableRoot helper built on the existing filterSingleRoot, and still warns correctly for non-element teleported content. On tests, Patch B is clearly stronger. Its unit tests cover the full enter/leave lifecycle with element assertions, appear hooks, out-in mode between two teleporting components, absence of the warning, and the still-warn case for text content. Patch A's unit tests are thinner: a KeepAlive test unrelated to the issue, an empty-Teleport test, and one hook-update test. Both add an essentially identical e2e test. Overall the fixes are comparable in correctness, but B is more centralized, safer at edge cases, and much better tested.

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

12m 29s

Wall-clock time in the container

Full test suite

No new failures

3,639 passed · 6 skipped · 3,645 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

221vs 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+220 −1
packages/runtime-core/__tests__/components/BaseTransition.spec.tsindex c541d5fc4..870309bb8 100644@@ -2,6 +2,7 @@ import {   BaseTransition,   type BaseTransitionProps,   KeepAlive,+  Teleport,   type TestElement,   type VNodeProps,   h,@@ -1293,4 +1294,115 @@ describe('BaseTransition', () => {     await runTestWithKeepAlive(testOutIn)     __DEV__ = true   })++  // #11834+  describe('w/ component rendering Teleport as root', () => {+    test('toggle on-off calls enter/leave hooks on teleported content', async () => {+      const target = nodeOps.createElement('div')+      const Modal = ({ msg }: { msg: string }) =>+        h(Teleport, { to: target }, [h('div', msg)])+      const toggle = ref(false)+      const { props, cbs } = mockProps()+      const { root } = mount(props, () =>+        toggle.value ? h(Modal, { msg: 'modal' }) : null,+      )+      expect(serializeInner(root)).toBe(`<!---->`)++      toggle.value = true+      await nextTick()+      expect(serializeInner(target)).toBe(`<div>modal</div>`)+      expect(props.onBeforeEnter).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onBeforeEnter, `<div>modal</div>`)+      expect(props.onEnter).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onEnter, `<div>modal</div>`)+      expect(props.onAfterEnter).not.toHaveBeenCalled()+      cbs.doneEnter[`<div>modal</div>`]()+      expect(props.onAfterEnter).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onAfterEnter, `<div>modal</div>`)++      toggle.value = false+      await nextTick()+      // stays in the teleport target until leave finishes+      expect(serializeInner(target)).toBe(`<div>modal</div>`)+      expect(props.onBeforeLeave).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onBeforeLeave, `<div>modal</div>`)+      expect(props.onLeave).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onLeave, `<div>modal</div>`)+      expect(props.onAfterLeave).not.toHaveBeenCalled()+      cbs.doneLeave[`<div>modal</div>`]()+      expect(serializeInner(target)).toBe(``)+      expect(props.onAfterLeave).toHaveBeenCalledTimes(1)++      assertCalls(props, {+        onBeforeEnter: 1,+        onEnter: 1,+        onAfterEnter: 1,+        onEnterCancelled: 0,+        onBeforeLeave: 1,+        onLeave: 1,+        onAfterLeave: 1,+        onLeaveCancelled: 0,+      })+      expect(+        'renders non-element root node that cannot be animated',+      ).not.toHaveBeenWarned()+    })++    test('appear calls appear hooks on teleported content', () => {+      const target = nodeOps.createElement('div')+      const Modal = {+        render: () => h(Teleport, { to: target }, [h('div', 'modal')]),+      }+      const { props, cbs } = mockProps({ appear: true })+      mount(props, () => h(Modal))+      expect(serializeInner(target)).toBe(`<div>modal</div>`)+      expect(props.onBeforeAppear).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onBeforeAppear, `<div>modal</div>`)+      expect(props.onAppear).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onAppear, `<div>modal</div>`)+      cbs.doneEnter[`<div>modal</div>`]()+      expect(props.onAfterAppear).toHaveBeenCalledTimes(1)+      expect(+        'renders non-element root node that cannot be animated',+      ).not.toHaveBeenWarned()+    })++    test('mode: "out-in" between teleporting components', async () => {+      const target = nodeOps.createElement('div')+      const CompA = () => h(Teleport, { to: target }, [h('div', 'a')])+      const CompB = () => h(Teleport, { to: target }, [h('span', 'b')])+      const toggle = ref(true)+      const { props, cbs } = mockProps({ mode: 'out-in' })+      mount(props, () => (toggle.value ? h(CompA) : h(CompB)))+      expect(serializeInner(target)).toBe(`<div>a</div>`)++      toggle.value = false+      await nextTick()+      expect(props.onLeave).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onLeave, `<div>a</div>`)+      // enter should not start until leave finishes+      expect(props.onBeforeEnter).not.toHaveBeenCalled()+      expect(serializeInner(target)).toBe(`<div>a</div>`)+      cbs.doneLeave[`<div>a</div>`]()+      expect(props.onAfterLeave).toHaveBeenCalledTimes(1)+      await nextTick()+      expect(serializeInner(target)).toBe(`<span>b</span>`)+      expect(props.onBeforeEnter).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onBeforeEnter, `<span>b</span>`)+      expect(props.onEnter).toHaveBeenCalledTimes(1)+      assertCalledWithEl(props.onEnter, `<span>b</span>`)+      cbs.doneEnter[`<span>b</span>`]()+      expect(props.onAfterEnter).toHaveBeenCalledTimes(1)+    })++    test('should still warn when teleported content is not an element', () => {+      const target = nodeOps.createElement('div')+      const Comp = () => h(Teleport, { to: target }, ['text' as any])+      const { props } = mockProps()+      mount(props, () => h(Comp))+      expect(+        'renders non-element root node that cannot be animated',+      ).toHaveBeenWarned()+    })+  }) })packages/runtime-core/src/componentRenderUtils.tsindex 0b46130c0..0b3feb8e8 100644@@ -255,7 +255,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 +368,18 @@ const isElementRoot = (vnode: VNode) => {   ) } +const isTransitionableRoot = (vnode: VNode): boolean => {+  // a Teleport root forwards transition hooks to its teleported content+  if (+    vnode.shapeFlag & ShapeFlags.TELEPORT &&+    vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN+  ) {+    const child = filterSingleRoot(vnode.children as VNodeArrayChildren, false)+    return !!child && isTransitionableRoot(child)+  }+  return !!isElementRoot(vnode)+}+ export function shouldUpdateComponent(   prevVNode: VNode,   nextVNode: VNode,packages/runtime-core/src/components/BaseTransition.tsindex 4a9d5098e..519f2bc32 100644@@ -12,6 +12,7 @@ import {   cloneVNode,   createCommentVNode,   isSameVNodeType,+  isVNode, } from '../vnode' import { warn } from '../warning' import { isKeepAlive } from './KeepAlive'@@ -542,6 +543,20 @@ 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 &&+    vnode.shapeFlag & ShapeFlags.ARRAY_CHILDREN+  ) {+    // a Teleport (e.g. the root of a component nested in <Transition>) does+    // not render an element itself, so forward the hooks to its content.+    // the hooks must not be set on the Teleport vnode itself, otherwise its+    // removal would fire `afterLeave` before the content has left.+    const children = vnode.children as VNode[]+    const child = children.length ? findNonCommentChild(children) : undefined+    // children may not be normalized yet (e.g. raw strings from h())+    if (isVNode(child)) {+      setTransitionHooks(child, hooks)+    }   } else {     vnode.transition = hooks   }packages/vue/__tests__/e2e/Transition.spec.tsindex 17519e832..523495bec 100644@@ -2782,6 +2782,86 @@ describe('e2e: Transition', () => {       },       E2E_TIMEOUT,     )+    // #11834+    test(+      'apply transition to teleport child of a custom component',+      async () => {+        await page().evaluate(() => {+          const { createApp, ref } = (window as any).Vue+          createApp({+            template: `+            <div id="target"></div>+            <div id="container">+              <transition>+                <Modal v-if="toggle" />+              </transition>+            </div>+            <button id="toggleBtn" @click="click">button</button>+          `,+            components: {+              Modal: {+                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', () => { 
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', () => {