From: huangcheng <1530844743@qq.com> Date: Thu, 12 May 2022 23:49:51 +0000 (+0800) Subject: fix(runtime-core): handle NaN identity check in v-memo (#5852) X-Git-Tag: v3.2.34-beta.1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3881299e98de6217f05bbd42ac509e8cc8be3d9;p=thirdparty%2Fvuejs%2Fcore.git fix(runtime-core): handle NaN identity check in v-memo (#5852) fix #5853 --- diff --git a/packages/runtime-core/__tests__/helpers/withMemo.spec.ts b/packages/runtime-core/__tests__/helpers/withMemo.spec.ts index 6a1a9ae2ee..9b7fcfc017 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 3e40365ea3..002b9e27a8 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 } }