diff --git a/packages/runtime-core/__tests__/helpers/withMemo.spec.ts b/packages/runtime-core/__tests__/helpers/withMemo.spec.ts index 6a1a9ae2ee6..9b7fcfc017f 100644 --- a/packages/runtime-core/__tests__/helpers/withMemo.spec.ts +++ b/packages/runtime-core/__tests__/helpers/withMemo.spec.ts @@ -210,4 +210,17 @@ describe('v-memo', () => { // should update expect(el.innerHTML).toBe(`
2
2
2
`) }) + + test('v-memo dependency is NaN should be equal', async () => { + const [el, vm] = mount({ + template: `
{{ y }}
`, + data: () => ({ x: NaN, y: 0 }) + }) + expect(el.innerHTML).toBe(`
0
`) + + vm.y++ + // should not update + await nextTick() + expect(el.innerHTML).toBe(`
0
`) + }) }) diff --git a/packages/runtime-core/src/helpers/withMemo.ts b/packages/runtime-core/src/helpers/withMemo.ts index 3e40365ea3f..002b9e27a88 100644 --- a/packages/runtime-core/src/helpers/withMemo.ts +++ b/packages/runtime-core/src/helpers/withMemo.ts @@ -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 } }