]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): handle NaN identity check in v-memo (#5852)
authorhuangcheng <1530844743@qq.com>
Thu, 12 May 2022 23:49:51 +0000 (07:49 +0800)
committerGitHub <noreply@github.com>
Thu, 12 May 2022 23:49:51 +0000 (19:49 -0400)
fix #5853

packages/runtime-core/__tests__/helpers/withMemo.spec.ts
packages/runtime-core/src/helpers/withMemo.ts

index 6a1a9ae2ee66affcaea092d71975732a95d53eca..9b7fcfc017f4a1dcc4218550d963941557f68db6 100644 (file)
@@ -210,4 +210,17 @@ describe('v-memo', () => {
     // should update
     expect(el.innerHTML).toBe(`<div>2</div><div>2</div><div>2</div>`)
   })
+
+  test('v-memo dependency is NaN should be equal', async () => {
+    const [el, vm] = mount({
+      template: `<div v-memo="[x]">{{ y }}</div>`,
+      data: () => ({ x: NaN, y: 0 })
+    })
+    expect(el.innerHTML).toBe(`<div>0</div>`)
+
+    vm.y++
+    // should not update
+    await nextTick()
+    expect(el.innerHTML).toBe(`<div>0</div>`)
+  })
 })
index 3e40365ea3f34703add68e91300f87d18dac90e1..002b9e27a88110caea3128d9a578d0d29b9b126d 100644 (file)
@@ -1,3 +1,4 @@
+import { hasChanged } from '@vue/shared'
 import { currentBlock, isBlockTreeEnabled, VNode } from '../vnode'
 
 export function withMemo(
@@ -22,8 +23,9 @@ export function isMemoSame(cached: VNode, memo: any[]) {
   if (prev.length != memo.length) {
     return false
   }
+  
   for (let i = 0; i < prev.length; i++) {
-    if (prev[i] !== memo[i]) {
+    if (hasChanged(prev[i], memo[i])) {
       return false
     }
   }