Skip to content

Commit

Permalink
fix(v-memo): should work on v-for with constant expression (#4272)
Browse files Browse the repository at this point in the history
fix #4246
  • Loading branch information
edison1105 authored Aug 7, 2021
1 parent c421fb9 commit 3b60358
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/runtime-core/__tests__/helpers/withMemo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,26 @@ describe('v-memo', () => {
`<div>5 yes z</div><div>2 no z</div><div>3 no z</div>`
)
})

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]">
{{count}}
</div>`,
data: () => ({
count: 0
})
})
expect(el.innerHTML).toBe(`<div>0</div><div>0</div><div>0</div>`)

vm.count = 1
await nextTick()
// should not update
expect(el.innerHTML).toBe(`<div>0</div><div>0</div><div>0</div>`)

vm.count = 2
await nextTick()
// should update
expect(el.innerHTML).toBe(`<div>2</div><div>2</div><div>2</div>`)
})
})
2 changes: 1 addition & 1 deletion packages/runtime-core/src/helpers/renderList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit 3b60358

Please sign in to comment.