Backtestsvuerun-20261021-133314#12569

Issue #12569 Merged fix PR # Run 21 Oct 2026 · run-20261021-133314 vuejs/core

Custom directive's unmounted event is not triggered on v-for element

Worse

The merged fix was judged better than our patch.

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

Both patches identify the same root cause: transformElement skips NEED_PATCH for elements it compiles as blocks (keyed elements, elements with runtime directives/vnode hooks plus children), and transformFor then demotes those blocks to plain vnodes inside a stable fragment without restoring the flag, so the vnode is never in the parent block's dynamicChildren and optimized unmount never runs the directive's unmounted hook. Both add NEED_PATCH back at demotion time, and both pass all five independent reproduction tests.

Patch A does this with a new `needsPatchWithoutBlock` helper that re-inspects the VNodeCall's props/directives from inside vFor. It is small and localized, but it duplicates buildProps's own analysis (hasRef/hasVnodeHook/runtimeDirectives) in a second place that can drift, and it unconditionally demotes the block. That discards a guarantee buildProps deliberately encodes: elements with a runtime directive or vue:before-update hook plus children are forced into blocks specifically so beforeUpdate runs before children patch. Under A, `<div v-for="i in 3" v-dir><span>{{x}}</span></div>` becomes a non-block vnode whose children are tracked ahead of it in dynamicChildren, so hooks now fire but in the wrong order.

Patch B threads the decision data out of buildProps (`needsPatch`, `isBlockRequired`) onto the VNodeCall, so vFor uses the same analysis the element transform used rather than re-deriving it. It only demotes when the block was not required for ordering, and keeps the block (which is still tracked by the parent block) when a before-update hook or directive with children needs it. It also correctly recomputes needsPatch after transformElement may have added TEXT, and tests that case. The hasRef reorder (so setup-const function refs are tracked) and the camelized `vue:beforeUpdate` match are adjacent fixes outside the issue's ask, but they are coherent with the same root cause, are covered by tests, and don't add meaningful risk. B is more invasive (ast.ts field additions, buildProps return shape), which costs it some scope/craft points, and the shadowed `needsPatch` plus `as PatchFlags` cast are slightly awkward.

Tests: both add compiler-level assertions and runtime integration tests that fail on base. B's tests additionally cover the ordering and non-NEED_PATCH cases that distinguish the approaches.

On balance B resolves the issue more correctly: it restores tracking without breaking the before-update ordering invariant the compiler already relies on, and it uses a single source of truth for the decision. A is a reasonable minimal fix but leaves a semantic regression path in the demoted-block case.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

13m 15s

Wall-clock time in the container

Full test suite

No new failures

1,865 passed · 1 skipped · 1,866 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

258vs 338 merged

Changed lines, ours vs merged

The two patches

Our patch+257 −1
packages/compiler-core/__tests__/transforms/vFor.spec.tsindex 839d9d358..da79fd22c 100644@@ -3,6 +3,7 @@ import { transform } from '../../src/transform' import { transformIf } from '../../src/transforms/vIf' import { transformFor } from '../../src/transforms/vFor' import { transformBind } from '../../src/transforms/vBind'+import { transformOn } from '../../src/transforms/vOn' import { transformElement } from '../../src/transforms/transformElement' import { transformSlotOutlet } from '../../src/transforms/transformSlotOutlet' import { transformExpression } from '../../src/transforms/transformExpression'@@ -15,6 +16,7 @@ import {   NodeTypes,   type RootNode,   type SimpleExpressionNode,+  type VNodeCall, } from '../../src/ast' import { ErrorCodes } from '../../src/errors' import { type CompilerOptions, generate } from '../../src'@@ -1118,6 +1120,100 @@ describe('compiler: v-for', () => {       expect(generate(root).code).toMatchSnapshot()     }) +    // #12569+    describe('stable v-for children demoted from blocks', () => {+      const getInnerVNodeCall = (template: string) => {+        const {+          node: { codegenNode },+        } = parseWithForTransform(template, {+          prefixIdentifiers: true,+          directiveTransforms: { bind: transformBind, on: transformOn },+        })+        expect(codegenNode.patchFlag).toBe(PatchFlags.STABLE_FRAGMENT)+        return (codegenNode.children.arguments[1] as any).returns as VNodeCall+      }++      test('keyed element with custom directive', () => {+        expect(+          getInnerVNodeCall('<div v-for="i in 3" :key="i" v-foo/>'),+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('element with custom directive and children', () => {+        expect(+          getInnerVNodeCall('<div v-for="i in 3" v-foo><span/></div>'),+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('keyed template v-for child with custom directive', () => {+        expect(+          getInnerVNodeCall(+            '<template v-for="i in 3" :key="i"><div v-foo><span/></div></template>',+          ),+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('keyed element with ref', () => {+        expect(+          getInnerVNodeCall('<div v-for="i in 3" :key="i" ref="el"/>'),+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('keyed element with cached vnode hook', () => {+        const {+          node: { codegenNode },+        } = parseWithForTransform(+          '<div v-for="i in 3" :key="i" @vue:unmounted="onUnmounted"/>',+          {+            prefixIdentifiers: true,+            cacheHandlers: true,+            directiveTransforms: { bind: transformBind, on: transformOn },+          },+        )+        expect(+          (codegenNode.children.arguments[1] as any).returns,+        ).toMatchObject({+          isBlock: false,+          patchFlag: PatchFlags.NEED_PATCH,+        })+      })++      test('keyed element without anything to patch stays untracked', () => {+        expect(+          getInnerVNodeCall('<div v-for="i in 3" :key="i"/>'),+        ).toMatchObject({+          isBlock: false,+          patchFlag: undefined,+        })+      })++      test('non-stable v-for children remain blocks', () => {+        const {+          node: { codegenNode },+        } = parseWithForTransform('<div v-for="i in list" :key="i" v-foo/>', {+          prefixIdentifiers: true,+        })+        expect(+          (codegenNode.children.arguments[1] as any).returns,+        ).toMatchObject({+          isBlock: true,+          patchFlag: undefined,+        })+      })+    })+     test('template v-for key w/ :key shorthand on div', () => {       const {         node: { codegenNode },packages/compiler-core/src/transforms/vFor.tsindex dcc31a9a9..fed735042 100644@@ -38,6 +38,7 @@ import {   injectProp,   isSlotOutlet,   isTemplateNode,+  needsPatchWithoutBlock, } from '../utils' import {   FRAGMENT,@@ -200,6 +201,18 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(               )             }           }+          if (+            isStableFragment &&+            childBlock.isBlock &&+            needsPatchWithoutBlock(childBlock)+          ) {+            // the element was compiled as a block and thus skipped NEED_PATCH.+            // now that it becomes a plain vnode in a stable fragment, it must+            // be tracked as a dynamic child so that its directives / refs /+            // vnode hooks are invoked on update and unmount.+            childBlock.patchFlag =+              (childBlock.patchFlag || 0) | PatchFlags.NEED_PATCH+          }           childBlock.isBlock = !isStableFragment           if (childBlock.isBlock) {             helper(OPEN_BLOCK)packages/compiler-core/src/utils.tsindex 025f6c32d..ace28a2c3 100644@@ -37,7 +37,14 @@ import {   TO_HANDLERS,   WITH_MEMO, } from './runtimeHelpers'-import { NOOP, isObject, isString } from '@vue/shared'+import {+  NOOP,+  PatchFlags,+  isObject,+  isOn,+  isReservedProp,+  isString,+} from '@vue/shared' import type { PropsExpression } from './transforms/transformElement' import { parseExpression } from '@babel/parser' import type { Expression, Node } from '@babel/types'@@ -602,6 +609,36 @@ export function getMemoedVNodeCall(   } } +/**+ * Elements compiled as blocks skip the NEED_PATCH flag for refs, vnode hooks+ * and runtime directives, since blocks are always tracked by their parent+ * block. If such a block is later demoted to a plain vnode (the child of a+ * stable v-for fragment), it must still be tracked as a dynamic child so that+ * these get updated and cleaned up on unmount.+ */+export function needsPatchWithoutBlock(node: VNodeCall): boolean {+  if (+    node.patchFlag !== undefined &&+    node.patchFlag !== PatchFlags.NEED_HYDRATION+  ) {+    // already tracked via its own patch flag+    return false+  }+  if (node.directives) {+    return true+  }+  const { props } = node+  return (+    !!props &&+    props.type === NodeTypes.JS_OBJECT_EXPRESSION &&+    props.properties.some(({ key }) => {+      if (!isStaticExp(key)) return false+      const name = key.content+      return name === 'ref' || (isOn(name) && isReservedProp(name))+    })+  )+}+ export const forAliasRE: RegExp = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/  export function isAllWhitespace(str: string): boolean {packages/vue/__tests__/index.spec.tsindex 79e48b775..8990bf50b 100644@@ -1,6 +1,19 @@ import { EMPTY_ARR } from '@vue/shared'+import { compile } from '@vue/compiler-dom'+import * as Vue from '../src' import { createApp, nextTick, reactive, ref } from '../src' +// compile like SFCs do (with prefixIdentifiers), which allows constant v-for+// sources to be compiled as stable fragments+function compileWithPrefixIdentifiers(template: string) {+  const { code } = compile(template, {+    hoistStatic: true,+    prefixIdentifiers: true,+    cacheHandlers: true,+  })+  return new Function('Vue', code)(Vue)+}+ describe('compiler + runtime integration', () => {   it('should support runtime template compilation', () => {     const container = document.createElement('div')@@ -293,6 +306,103 @@ describe('compiler + runtime integration', () => {     expect(container.innerHTML).toBe(`<div>2<div>1</div></div>`)   }) +  // #12569+  test('custom directive hooks on elements in v-for with constant source', async () => {+    const visible = ref(true)+    const msg = ref('a')+    const calls: string[] = []+    const vFocus = {+      mounted: (el: Element) => calls.push(`mounted ${el.tagName}`),+      updated: (el: Element) => calls.push(`updated ${el.tagName}`),+      unmounted: (el: Element) => calls.push(`unmounted ${el.tagName}`),+    }+    const App = {+      setup() {+        return { visible, msg }+      },+      directives: { focus: vFocus },+      render: compileWithPrefixIdentifiers(+        `<template v-if="visible">` ++          `<h1 v-for="i in 2" :key="i" v-focus>{{ msg }}</h1>` ++          `<p v-for="i in 2" v-focus>{{ msg }}</p>` ++          `<span v-for="i in 2" :key="i" v-focus/>` ++          `</template>` ++          `<div v-focus v-if="visible">my tag</div>`,+      ),+    }+    const container = document.createElement('div')+    createApp(App).mount(container)+    expect(calls).toEqual([+      'mounted H1',+      'mounted H1',+      'mounted P',+      'mounted P',+      'mounted SPAN',+      'mounted SPAN',+      'mounted DIV',+    ])++    calls.length = 0+    msg.value = 'b'+    await nextTick()+    expect(container.innerHTML).toContain('<h1>b</h1>')+    expect(calls).toEqual([+      'updated H1',+      'updated H1',+      'updated P',+      'updated P',+      'updated SPAN',+      'updated SPAN',+      'updated DIV',+    ])++    calls.length = 0+    visible.value = false+    await nextTick()+    expect(container.innerHTML).toBe(`<!--v-if--><!--v-if-->`)+    expect(calls).toEqual([+      'unmounted H1',+      'unmounted H1',+      'unmounted P',+      'unmounted P',+      'unmounted SPAN',+      'unmounted SPAN',+      'unmounted DIV',+    ])+  })++  // #12569+  test('refs and vnode hooks on keyed elements in v-for with constant source', async () => {+    const visible = ref(true)+    const unmounted: number[] = []+    let instance: any+    const App = {+      setup() {+        return {+          visible,+          onUnmounted: (vnode: any) => unmounted.push(vnode.key),+        }+      },+      mounted(this: any) {+        instance = this+      },+      render: compileWithPrefixIdentifiers(+        `<div v-if="visible">` ++          `<span v-for="i in 2" :key="i" ref="items"/>` ++          `<i v-for="i in 2" :key="i" @vue:unmounted="onUnmounted"/>` ++          `</div>`,+      ),+    }+    const container = document.createElement('div')+    createApp(App).mount(container)+    expect(instance.$refs.items.length).toBe(2)++    visible.value = false+    await nextTick()+    expect(instance.$refs.items).toEqual([])+    expect(unmounted).toEqual([1, 2])+  })+   test('nullish v-bind on <slot>', async () => {     const Child = {       props: ['error', 'value'], 
Merged fix · PR #+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()+    })+  }) })