diff --git a/packages/runtime-core/__tests__/helpers/withMemo.spec.ts b/packages/runtime-core/__tests__/helpers/withMemo.spec.ts index b98b8c29..93aac0d8 100644 --- a/packages/runtime-core/__tests__/helpers/withMemo.spec.ts +++ b/packages/runtime-core/__tests__/helpers/withMemo.spec.ts @@ -147,4 +147,26 @@ describe('v-memo', () => { `
5 yes z
2 no z
3 no z
` ) }) + + test('on v-for /w constant expression ', async () => { + const [el, vm] = mount({ + template: `
+ {{count}} +
`, + data: () => ({ + count: 0 + }) + }) + expect(el.innerHTML).toBe(`
0
0
0
`) + + vm.count = 1 + await nextTick() + // should not update + expect(el.innerHTML).toBe(`
0
0
0
`) + + vm.count = 2 + await nextTick() + // should update + expect(el.innerHTML).toBe(`
2
2
2
`) + }) }) diff --git a/packages/runtime-core/src/helpers/renderList.ts b/packages/runtime-core/src/helpers/renderList.ts index 543c343d..9fbf967a 100644 --- a/packages/runtime-core/src/helpers/renderList.ts +++ b/packages/runtime-core/src/helpers/renderList.ts @@ -71,7 +71,7 @@ export function renderList( } ret = new Array(source) for (let i = 0; i < source; i++) { - ret[i] = renderItem(i + 1, i) + ret[i] = renderItem(i + 1, i, undefined, cached && cached[i]) } } else if (isObject(source)) { if (source[Symbol.iterator as any]) {