Backtestsvuerun-20261013-093701#9239

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

the div which has the ref attribute inside the v-for, when I v-if toggle them, the ref value.length increase more and more

Better

Our patch was judged better than the merged fix.

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

Both patches fix the same root cause. In a stable v-for, a child with a dynamic `:key` is first built as a block, so `transformElement` leaves out NEED_PATCH. vFor then demotes it to a plain vnode with no patch flag. The vnode is therefore missing from the parent's dynamicChildren, and block-tree unmount never runs its ref cleanup. That is why the ref array keeps growing.

Patch A fixes this where the demotion happens, in vFor. After switching the child from block to vnode, it adds NEED_PATCH if the vnode has directives, a `ref` prop, or an onVnodeXXX prop, and has no other tracking patch flag. The helper is small and self-contained, has a clear comment, and changes nothing else in the compiler. It checks the generated props object directly, so it also catches constant or cached refs and vnode hooks that `buildProps` returns early on. Its tests are direct: compiler tests assert NEED_PATCH on the demoted child, including a negative case. Integration tests toggle v-if repeatedly and check the ref array goes 3→0→3 each cycle, which is exactly the reported bug. They also cover dynamic ref updates, directive updated/unmounted hooks, and vnode unmount hooks.

Patch B also fixes the issue, but more invasively. It adds two new fields to the VNodeCall AST (`needsPatch`, `isBlockRequired`) and restructures `buildProps`: it moves `hasRef` detection, changes before-update hook matching to camelize, and adds a separate block-required path. It also changes stable-fragment semantics by keeping some children as blocks when they have before-update hooks with children. That is a separate behavioral change outside the issue's ask, and it carries regression risk in shared compiler code. Its tests are thorough and include the beforeUpdate ordering cases. However, the issue-specific test toggles only once, while Patch A's loops through repeated toggles.

On correctness for the reported scenario the two are roughly equal. Patch A is narrower, easier to verify, and its tests target the regression more directly. Patch B's extra redesign earns no credit and adds risk, so A is the better 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

11m 10s

Wall-clock time in the container

Full test suite

No new failures

1,863 passed · 1 skipped · 1,864 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

206vs 338 merged

Changed lines, ours vs merged

Vue version

3.2.47

Link to minimal reproduction

https://play.vuejs.org/#eNqtVUtv00AQ/iuDOSSV0qSot9QttNADSDxEERfMwbUnzjab3dU+3ESR/zuz68R2nNIglR6a3Z1v5pu3N9G1UuPSYTSNYpNppiwYtE4BT0VxmUTWJNFVIthSSW1hAxpnI/qXZpaVOAIpPksnLOYjyORSuXB6TG02hwpmWi5hQMYHjYH3BLrZCsaTcPPsBEhEJoWxwMxPZtg9R7j0ZEOrHZ4kYuYEUUoBVhYFxy1meAKbRECrNC5T7rzqq95TIqqWg+x+YOUdE2RpSyMc50TTyL1rTwH2TVxrvRX/+t3X7sniSZ1eSmZscal4apHOAHHOSjB2zZHSfS91jnoKb9QKjOQsh9eIeAEqzXPyhgRnahUqAvTnVa+6wUxhE0rURldV8cSj9hXa6HYanXh7KnMNk0M+im7MURR23uFsH5/hPdTcfz3G3zYIabeXtzBYoxnAFAZCDvpG7p211DzvMs6yhW/rbhdRPvfu8aSGk3LLC+Upm5Fmw5hETdXmyIq59cWh6lzAYRGV0yrw1PYATEj17hbsUyLIVLd4HTxh6tFpUG3BCBbXo9TA92Lv1eFlgTCx6LiVap2u96IoT2dSk6VhWZ6NgIkcV2cn9AvnRDNd4Nozh1e6d0OmBjgab435t2B3p3jSmbY4BAomkwrz3YrjaPySowH1QkJFI1p7NMszVowfjBS0G8OWSSK/4xhH/VX5XURa1MI1cRKlnMvHT+HN76zR7j2bY7Z44v3B0CBP6fBNo0FdUh0amU11gbYW3959wRWdG+FS5s5X7Rnhd6RyOe9jDbtxIie3O7jg7cewlKmJfpjblUVhdkF5Rz2yCvgkohXtc/630Ft3z8fnQY/WLWWx2e//7+vS+6wkosEM6WNweQWb6uiyzXhqDLE/6lT52UdjX9It1R+VZ24c

Steps to reproduce

if I click toggleVisible many times,

  1. the refDivSingle toggle between null and div
  2. the refCompSingle toggle between null and {}
  3. the refDivArr.length increase more and more <-- error here
  4. the refCompArr.length toggle between 3 and 0

if I use ref function, it don't get null
<img width="532" alt="image" src="https://github.com/vuejs/core/assets/417448/b1a09a97-2c9f-4310-9430-27aa04b79863">

What is expected?

the refDivArr.length should toggle between 3 and 0, same as the refCompArr.length

What is actually happening?

the refDivArr.length increase more and more

System Info

_No response_

Any additional comments?

_No response_

The two patches

Our patch+205 −1
packages/compiler-core/__tests__/transforms/vFor.spec.tsindex 839d9d358..3bbd65124 100644@@ -1143,5 +1143,69 @@ describe('compiler: v-for', () => {         },       })     })++    // #8384+    describe('stable fragment child demoted from block', () => {+      const getInnerVNodeCall = (template: string) => {+        const {+          node: { codegenNode },+        } = parseWithForTransform(template, { prefixIdentifiers: true })+        return assertSharedCodegen(+          codegenNode,+          true,+          false,+          false /* stable fragment */,+        ).innerVNodeCall+      }++      test('keyed element w/ ref', () => {+        expect(+          getInnerVNodeCall(+            `<div v-for="i in 3" :key="i" ref="el"><span/></div>`,+          ),+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('keyed element w/ dynamic ref', () => {+        expect(+          getInnerVNodeCall(`<div v-for="i in 3" :key="i" :ref="el" />`),+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('keyed template v-for w/ ref on child', () => {+        expect(+          getInnerVNodeCall(+            `<template v-for="i in 3" :key="i"><div ref="el"/></template>`,+          ),+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('element w/ custom directive and children', () => {+        expect(+          getInnerVNodeCall(`<div v-for="i in 3" :key="i" v-foo><span/></div>`),+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('keyed element w/o ref/directives stays without patch flag', () => {+        expect(+          getInnerVNodeCall(`<div v-for="i in 3" :key="i"><span/></div>`),+        ).toMatchObject({+          isBlock: false,+          patchFlag: undefined,+        })+      })+    })   }) })packages/compiler-core/src/transforms/vFor.tsindex dcc31a9a9..8577edca5 100644@@ -47,7 +47,7 @@ import { } from '../runtimeHelpers' import { processExpression } from './transformExpression' import { validateBrowserExpression } from '../validateExpression'-import { PatchFlags } from '@vue/shared'+import { PatchFlags, isOn, isReservedProp } from '@vue/shared'  export const transformFor: NodeTransform = createStructuralDirectiveTransform(   'for',@@ -193,6 +193,15 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(               removeHelper(                 getVNodeBlockHelper(context.inSSR, childBlock.isComponent),               )+              // #8384 transformElement omits NEED_PATCH for blocks (e.g.+              // elements with a dynamic key) since blocks are always tracked.+              // Once demoted to a plain vnode it must carry the flag, otherwise+              // it's skipped by block-tree patch / unmount and its ref,+              // vnode hooks and directives are never updated or cleaned up.+              if (needsPatchFlagAsVNode(childBlock)) {+                childBlock.patchFlag =+                  (childBlock.patchFlag || 0) | PatchFlags.NEED_PATCH+              }             } else {               // switch from vnode to block               removeHelper(@@ -391,3 +400,26 @@ function createParamsList(     .slice(0, i + 1)     .map((arg, i) => arg || createSimpleExpression(`_`.repeat(i + 1), false)) }++function needsPatchFlagAsVNode(node: VNodeCall): boolean {+  const { patchFlag, props, directives } = node+  // any other patch flag already ensures the vnode is tracked+  if (patchFlag && patchFlag !== PatchFlags.NEED_HYDRATION) {+    return false+  }+  if (directives) {+    return true+  }+  return (+    !!props &&+    props.type === NodeTypes.JS_OBJECT_EXPRESSION &&+    props.properties.some(({ key }) => {+      if (key.type !== NodeTypes.SIMPLE_EXPRESSION || !key.isStatic) {+        return false+      }+      const name = key.content+      // template ref, or onVnodeXXX hooks+      return name === 'ref' || (isOn(name) && isReservedProp(name))+    })+  )+}packages/vue/__tests__/index.spec.tsindex 79e48b775..6b0d5ca74 100644@@ -1,4 +1,6 @@ import { EMPTY_ARR } from '@vue/shared'+import { compile } from '@vue/compiler-dom'+import * as Vue from '../src' import { createApp, nextTick, reactive, ref } from '../src'  describe('compiler + runtime integration', () => {@@ -347,4 +349,110 @@ describe('compiler + runtime integration', () => {     app.mount(root)     expect(root.innerHTML).toBe('<div>60000000100000111</div>')   })++  // #8384 compile in prefixIdentifiers mode (as SFCs do) so that v-for over+  // a constant source produces a stable fragment+  describe('keyed v-for over constant source', () => {+    const compileWithPrefix = (template: string) =>+      new Function(+        'Vue',+        compile(template, {+          mode: 'function',+          prefixIdentifiers: true,+          hoistStatic: true,+          cacheHandlers: true,+        }).code,+      )(Vue)++    test('ref array should be cleaned up on unmount', async () => {+      const show = ref(true)+      const divs = ref<Element[]>([])+      const App = {+        setup: () => ({ show, divs }),+        render: compileWithPrefix(+          `<div v-if="show">` ++            `<div v-for="(v, i) in 3" :key="i" ref="divs"><span/></div>` ++            `</div>`,+        ),+      }+      const container = document.createElement('div')+      createApp(App).mount(container)+      expect(divs.value.length).toBe(3)++      for (let i = 0; i < 3; i++) {+        show.value = false+        await nextTick()+        expect(divs.value.length).toBe(0)++        show.value = true+        await nextTick()+        expect(divs.value.length).toBe(3)+        expect(divs.value.every(el => container.contains(el))).toBe(true)+      }+    })++    test('dynamic ref should be updated', async () => {+      const name = ref('a')+      const refs = { a: ref<Element[]>([]), b: ref<Element[]>([]) }+      const App = {+        setup: () => ({ name, ...refs }),+        render: compileWithPrefix(+          `<div v-for="(v, i) in 3" :key="i" :ref="name"><span/></div>`,+        ),+      }+      const container = document.createElement('div')+      createApp(App).mount(container)+      expect(refs.a.value.length).toBe(3)+      expect(refs.b.value.length).toBe(0)++      name.value = 'b'+      await nextTick()+      expect(refs.b.value.length).toBe(3)+    })++    test('custom directive hooks should be called', async () => {+      const show = ref(true)+      const count = ref(0)+      const updated = vi.fn()+      const unmounted = vi.fn()+      const App = {+        directives: { foo: { updated, unmounted } },+        setup: () => ({ show, count }),+        render: compileWithPrefix(+          `<div v-if="show">` ++            `<div v-for="(v, i) in 3" :key="i" v-foo="count"><span/></div>` ++            `</div>`,+        ),+      }+      const container = document.createElement('div')+      createApp(App).mount(container)++      count.value+++      await nextTick()+      expect(updated).toHaveBeenCalledTimes(3)++      show.value = false+      await nextTick()+      expect(unmounted).toHaveBeenCalledTimes(3)+    })++    test('cached vnode hooks should be called on unmount', async () => {+      const show = ref(true)+      const onUnmounted = vi.fn()+      const App = {+        setup: () => ({ show, onUnmounted }),+        render: compileWithPrefix(+          `<div v-if="show">` ++            `<div v-for="(v, i) in 3" :key="i" @vue:unmounted="onUnmounted"><span/></div>` ++            `</div>`,+        ),+      }+      const container = document.createElement('div')+      createApp(App).mount(container)++      show.value = false+      await nextTick()+      expect(onUnmounted).toHaveBeenCalledTimes(3)+    })+  }) }) 
Merged fix · PR #11682+321 −17
packages/compiler-core/__tests__/transforms/transformElement.spec.tsindex bf3510a05..8215ceedb 100644@@ -74,6 +74,12 @@ function parseWithBind(template: string, options?: CompilerOptions) {   }) } +function getVForChild(+  node: ReturnType<typeof parseWithForTransform>['node'],+): VNodeCall {+  return node.codegenNode.children.arguments[1].returns as VNodeCall+}+ describe('compiler: element transform', () => {   test('import + resolve component', () => {     const { root } = parseWithElementTransform(`<Foo/>`)@@ -1028,6 +1034,105 @@ describe('compiler: element transform', () => {       expect(node.patchFlag).toBe(PatchFlags.NEED_PATCH)     }) +    test('NEED_PATCH (stable v-for + static ref)', () => {+      const { node } = parseWithForTransform(+        `<div v-for="i in 3" :key="i" ref="foo" />`,+        { prefixIdentifiers: true },+      )+      const child = getVForChild(node)+      expect(child.isBlock).toBe(false)+      expect(child.patchFlag).toBe(PatchFlags.NEED_PATCH)+    })++    test('NEED_PATCH (stable v-for + custom directives)', () => {+      const { node } = parseWithForTransform(+        `<div v-for="i in 3" :key="i" v-dir />`,+        { prefixIdentifiers: true },+      )+      const child = getVForChild(node)+      expect(child.isBlock).toBe(false)+      expect(child.patchFlag).toBe(PatchFlags.NEED_PATCH)+    })++    test('NEED_PATCH (stable v-for + vnode hooks)', () => {+      const { node } = parseWithForTransform(+        `<div v-for="i in 3" :key="i" @vue:unmounted="foo" />`,+        {+          prefixIdentifiers: true,+          cacheHandlers: true,+          directiveTransforms: {+            bind: transformBind,+            on: transformOn,+          },+        },+      )+      const child = getVForChild(node)+      expect(child.isBlock).toBe(false)+      expect(child.patchFlag).toBe(PatchFlags.NEED_PATCH)+    })++    test('NEED_PATCH (stable v-for + setup-const function ref)', () => {+      const { node } = parseWithForTransform(+        `<div v-for="i in 3" :key="i" :ref="setRefFn" />`,+        {+          prefixIdentifiers: true,+          bindingMetadata: {+            setRefFn: BindingTypes.SETUP_CONST,+          },+        },+      )+      const child = getVForChild(node)+      expect(child.isBlock).toBe(false)+      expect(child.patchFlag).toBe(PatchFlags.NEED_PATCH)+    })++    test('preserve block for stable v-for + custom directive with children', () => {+      const { node } = parseWithForTransform(+        `<div v-for="i in 3" v-dir>{{ i }}</div>`,+        { prefixIdentifiers: true },+      )+      const child = getVForChild(node)+      expect(child.isBlock).toBe(true)+      expect(child.patchFlag).toBe(PatchFlags.TEXT)+    })++    test.each(['before-update', 'beforeUpdate'])(+      'preserve block for stable v-for + @vue:%s vnode hook',+      hook => {+        const { node } = parseWithForTransform(+          `<div v-for="i in 3" @vue:${hook}="foo"><span /></div>`,+          {+            prefixIdentifiers: true,+            cacheHandlers: true,+            directiveTransforms: {+              bind: transformBind,+              on: transformOn,+            },+          },+        )+        const child = getVForChild(node)+        expect(child.isBlock).toBe(true)+        expect(child.patchFlag).toBeUndefined()+      },+    )++    test('does not add NEED_PATCH when another patch flag tracks the vnode', () => {+      const { node } = parseWithForTransform(+        `<div v-for="i in 3" :key="i" @vue:unmounted="foo">{{ i }}</div>`,+        {+          prefixIdentifiers: true,+          cacheHandlers: true,+          directiveTransforms: {+            bind: transformBind,+            on: transformOn,+          },+        },+      )+      const child = getVForChild(node)+      expect(child.isBlock).toBe(false)+      expect(child.patchFlag).toBe(PatchFlags.TEXT)+    })+     test('script setup inline mode template ref (binding exists)', () => {       const { node } = parseWithElementTransform(`<input ref="input"/>`, {         inline: true,packages/compiler-core/src/ast.tsindex e6da01edb..f67231539 100644@@ -330,6 +330,10 @@ export interface VNodeCall extends Node {   patchFlag: PatchFlags | undefined   dynamicProps: string | SimpleExpressionNode | undefined   directives: DirectiveArguments | undefined+  /** Whether this vnode must be patched if a later transform makes it non-block. */+  needsPatch?: boolean+  /** Whether a later transform must preserve this vnode as a block. */+  isBlockRequired?: boolean   isBlock: boolean   disableTracking: boolean   isComponent: booleanpackages/compiler-core/src/transforms/transformElement.tsindex 40f08d45b..b2024b329 100644@@ -102,6 +102,8 @@ export const transformElement: NodeTransform = (node, context) => {     let vnodeDynamicProps: VNodeCall['dynamicProps']     let dynamicPropNames: string[] | undefined     let vnodeDirectives: VNodeCall['directives']+    let needsPatch = false+    let isBlockRequired = false      let shouldUseBlock =       // dynamic component may resolve to plain elements@@ -127,6 +129,8 @@ export const transformElement: NodeTransform = (node, context) => {       vnodeProps = propsBuildResult.props       patchFlag = propsBuildResult.patchFlag       dynamicPropNames = propsBuildResult.dynamicPropNames+      needsPatch = propsBuildResult.needsPatch+      isBlockRequired = propsBuildResult.isBlockRequired       const directives = propsBuildResult.directives       vnodeDirectives =         directives && directives.length@@ -206,7 +210,7 @@ export const transformElement: NodeTransform = (node, context) => {       vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames)     } -    node.codegenNode = createVNodeCall(+    const vnodeCall = (node.codegenNode = createVNodeCall(       context,       vnodeTag,       vnodeProps,@@ -218,7 +222,15 @@ export const transformElement: NodeTransform = (node, context) => {       false /* disableTracking */,       isComponent,       node.loc,-    )+    ))+    needsPatch =+      needsPatch && (patchFlag === 0 || patchFlag === PatchFlags.NEED_HYDRATION)+    if (needsPatch) {+      vnodeCall.needsPatch = true+    }+    if (isBlockRequired) {+      vnodeCall.isBlockRequired = true+    }   } } @@ -382,6 +394,8 @@ export function buildProps(   patchFlag: number   dynamicPropNames: string[]   shouldUseBlock: boolean+  needsPatch: boolean+  isBlockRequired: boolean } {   const { tag, loc: elementLoc, children } = node   let properties: ObjectExpression['properties'] = []@@ -389,6 +403,7 @@ export function buildProps(   const runtimeDirectives: DirectiveNode[] = []   const hasChildren = children.length > 0   let shouldUseBlock = false+  let isBlockRequired = false    // patchFlag analysis   let patchFlag = 0@@ -444,6 +459,10 @@ export function buildProps(         hasVnodeHook = true       } +      if (name === 'ref') {+        hasRef = true+      }+       if (isEventHandler && value.type === NodeTypes.JS_CALL_EXPRESSION) {         // handler wrapped with internal helper e.g. withModifiers(fn)         // extract the actual expression@@ -460,13 +479,15 @@ export function buildProps(         return       } -      if (name === 'ref') {-        hasRef = true-      } else if (name === 'class') {+      if (name === 'class') {         hasClassBinding = true       } else if (name === 'style') {         hasStyleBinding = true-      } else if (name !== 'key' && !dynamicPropNames.includes(name)) {+      } else if (+        name !== 'ref' &&+        name !== 'key' &&+        !dynamicPropNames.includes(name)+      ) {         dynamicPropNames.push(name)       } @@ -573,14 +594,21 @@ export function buildProps(         continue       } +      // #938: elements with dynamic keys should be forced into blocks+      if (isVBind && isStaticArgOf(arg, 'key')) {+        shouldUseBlock = true+      }+      // inline before-update hooks need to remain blocks so that they are+      // invoked before children       if (-        // #938: elements with dynamic keys should be forced into blocks-        (isVBind && isStaticArgOf(arg, 'key')) ||-        // inline before-update hooks need to force block so that it is invoked-        // before children-        (isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))+        isVOn &&+        hasChildren &&+        arg &&+        isStaticExp(arg) &&+        camelize(arg.content) === 'vue:beforeUpdate'       ) {         shouldUseBlock = true+        isBlockRequired = true       }        if (isVBind && isStaticArgOf(arg, 'ref')) {@@ -691,6 +719,7 @@ export function buildProps(         // to ensure before-update gets called before children update         if (hasChildren) {           shouldUseBlock = true+          isBlockRequired = true         }       }     }@@ -736,11 +765,10 @@ export function buildProps(       patchFlag |= PatchFlags.NEED_HYDRATION     }   }-  if (-    !shouldUseBlock &&+  const needsPatch =     (patchFlag === 0 || patchFlag === PatchFlags.NEED_HYDRATION) &&     (hasRef || hasVnodeHook || runtimeDirectives.length > 0)-  ) {+  if (!shouldUseBlock && needsPatch) {     patchFlag |= PatchFlags.NEED_PATCH   } @@ -825,6 +853,8 @@ export function buildProps(     patchFlag,     dynamicPropNames,     shouldUseBlock,+    needsPatch,+    isBlockRequired,   } } packages/compiler-core/src/transforms/vFor.tsindex dcc31a9a9..ebf67d3d7 100644@@ -186,7 +186,9 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(           if (isTemplate && keyProperty) {             injectProp(childBlock, keyProperty, context)           }-          if (childBlock.isBlock !== !isStableFragment) {+          const shouldUseBlock =+            !isStableFragment || childBlock.isBlockRequired === true+          if (childBlock.isBlock !== shouldUseBlock) {             if (childBlock.isBlock) {               // switch from block to vnode               removeHelper(OPEN_BLOCK)@@ -200,12 +202,16 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(               )             }           }-          childBlock.isBlock = !isStableFragment+          childBlock.isBlock = shouldUseBlock           if (childBlock.isBlock) {             helper(OPEN_BLOCK)             helper(getVNodeBlockHelper(context.inSSR, childBlock.isComponent))           } else {             helper(getVNodeHelper(context.inSSR, childBlock.isComponent))+            if (childBlock.needsPatch) {+              childBlock.patchFlag = ((childBlock.patchFlag ?? 0) |+                PatchFlags.NEED_PATCH) as PatchFlags+            }           }         } packages/vue/__tests__/index.spec.tsindex 79e48b775..98f00cf28 100644@@ -1,5 +1,19 @@+import { BindingTypes, type CompilerOptions } from '@vue/compiler-core'+import { compile } from '@vue/compiler-dom' import { EMPTY_ARR } from '@vue/shared'-import { createApp, nextTick, reactive, ref } from '../src'+import { type VNode, createApp, nextTick, reactive, ref } from '../src'+import * as Vue from '../src'+import type { InternalRenderFunction } from '../../runtime-core/src/component'++function compileToFunction(template: string, options?: CompilerOptions) {+  const { code } = compile(template, {+    hoistStatic: true,+    ...options,+  })+  const render = new Function('Vue', code)(Vue) as InternalRenderFunction+  render._rc = true+  return render+}  describe('compiler + runtime integration', () => {   it('should support runtime template compilation', () => {@@ -347,4 +361,149 @@ describe('compiler + runtime integration', () => {     app.mount(root)     expect(root.innerHTML).toBe('<div>60000000100000111</div>')   })++  describe('stable v-for lifecycle', () => {+    test('clears static ref arrays on branch removal', async () => {+      const show = ref(true)+      const items = ref<HTMLElement[]>([])+      const app = createApp({+        setup: () => ({ items, show }),+        render: compileToFunction(+          `<template v-if="show"><div v-for="i in 3" :key="i" ref="items" /></template>`,+          { prefixIdentifiers: true },+        ),+      })+      const container = document.createElement('div')++      app.mount(container)+      expect(items.value).toHaveLength(3)++      show.value = false+      await nextTick()+      expect(items.value).toHaveLength(0)++      app.unmount()+    })++    test('calls setup-const function refs with null on branch removal', async () => {+      const show = ref(true)+      const values: (Element | null)[] = []+      const setRef = (value: Element | null) => values.push(value)+      const app = createApp({+        setup: () => ({ setRef, show }),+        render: compileToFunction(+          `<template v-if="show"><div v-for="i in 1" :ref="setRef" /></template>`,+          {+            prefixIdentifiers: true,+            bindingMetadata: {+              setRef: BindingTypes.SETUP_CONST,+            },+          },+        ),+      })+      const container = document.createElement('div')++      app.mount(container)+      expect(values).toHaveLength(1)+      expect(values[0]).toBeInstanceOf(HTMLDivElement)++      show.value = false+      await nextTick()+      expect(values).toHaveLength(2)+      expect(values[1]).toBeNull()++      app.unmount()+    })++    test('calls directive unmounted hooks on branch removal', async () => {+      const show = ref(true)+      const unmounted = vi.fn()+      const app = createApp({+        directives: { dir: { unmounted } },+        setup: () => ({ show }),+        render: compileToFunction(+          `<template v-if="show"><div v-for="i in 1" v-dir /></template>`,+          { prefixIdentifiers: true },+        ),+      })+      const container = document.createElement('div')++      app.mount(container)+      show.value = false+      await nextTick()+      expect(unmounted).toHaveBeenCalledOnce()++      app.unmount()+    })++    test('calls vnode unmounted hooks on branch removal', async () => {+      const show = ref(true)+      const onVnodeUnmounted = vi.fn()+      const app = createApp({+        setup: () => ({ onVnodeUnmounted, show }),+        render: compileToFunction(+          `<template v-if="show"><div v-for="i in 1" @vue:unmounted="onVnodeUnmounted" /></template>`,+          { prefixIdentifiers: true },+        ),+      })+      const container = document.createElement('div')++      app.mount(container)+      show.value = false+      await nextTick()+      expect(onVnodeUnmounted).toHaveBeenCalledOnce()++      app.unmount()+    })++    test('runs directive beforeUpdate before child updates', async () => {+      const value = ref('old')+      const observed: string[] = []+      const app = createApp({+        directives: {+          dir: {+            beforeUpdate(el: HTMLElement) {+              observed.push(el.textContent!)+            },+          },+        },+        setup: () => ({ value }),+        render: compileToFunction(+          `<div v-for="i in 1" v-dir>{{ value }}</div>`,+          { prefixIdentifiers: true },+        ),+      })+      const container = document.createElement('div')++      app.mount(container)+      value.value = 'new'+      await nextTick()+      expect(observed).toEqual(['old'])++      app.unmount()+    })++    test('runs vnode beforeUpdate before nested child updates', async () => {+      const value = ref('old')+      const observed: string[] = []+      const onVnodeBeforeUpdate = (vnode: VNode) => {+        observed.push((vnode.el as HTMLElement).textContent!)+      }+      const app = createApp({+        setup: () => ({ onVnodeBeforeUpdate, value }),+        render: compileToFunction(+          `<div v-for="i in 1" @vue:beforeUpdate="onVnodeBeforeUpdate"><span>{{ value }}</span></div>`,+          { prefixIdentifiers: true },+        ),+      })+      const container = document.createElement('div')++      app.mount(container)+      value.value = 'new'+      await nextTick()+      expect(observed).toEqual(['old'])++      app.unmount()+    })+  }) })