]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test: add test case edison/fix/vIfWorkWithVMemo 12710/head
authordaiwei <daiwei521@126.com>
Wed, 15 Jan 2025 05:57:18 +0000 (13:57 +0800)
committerdaiwei <daiwei521@126.com>
Wed, 15 Jan 2025 05:57:18 +0000 (13:57 +0800)
packages/runtime-core/__tests__/helpers/withMemo.spec.ts
packages/runtime-core/src/vnode.ts

index 32f89b1d8e9d6ace85387caf8a04e1353bfd14ef..cc447327e39159c06c04469edfc4d473285e6da5 100644 (file)
@@ -204,6 +204,32 @@ describe('v-memo', () => {
     )
   })
 
+  // #12708
+  test('v-memo should work correctly when toggling v-if with v-for inside', async () => {
+    const [el, vm] = mount({
+      template: `<span v-if="show">
+          <span v-for="elem in [1]" :key="elem" v-memo="[count]">{{count}}</span>
+        </span>`,
+      data: () => ({
+        show: true,
+        count: 0,
+      }),
+    })
+    expect(el.innerHTML).toBe(`<span><span>0</span></span>`)
+
+    vm.show = false
+    await nextTick()
+    expect(el.innerHTML).toBe(`<!--v-if-->`)
+
+    vm.show = true
+    await nextTick()
+    expect(el.innerHTML).toBe(`<span><span>0</span></span>`)
+
+    vm.count++
+    await nextTick()
+    expect(el.innerHTML).toBe(`<span><span>1</span></span>`)
+  })
+
   test('on v-for /w constant expression ', async () => {
     const [el, vm] = mount({
       template: `<div v-for="item in 3"  v-memo="[count < 2 ? true : count]">
index 97a9e8b234b8ed07a00f5497d523e8ec9b509848..34aea8f79cb2754638cb3da4120e46437262ea60 100644 (file)
@@ -243,7 +243,7 @@ export interface VNode<
   memo?: any[]
   /**
    * @internal index for cleaning v-memo cache
-   * cacheIndex will be an array when vnode in vFor
+   * cacheIndex will be an array when vnode in vFor + vMemo
    */
   cacheIndex?: number | number[]
   /**