Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, ({ x, y }, __, ___, _cached) => {
const _memo = ([x, y === _ctx.z])
if (_cached && _cached.el && _cached.key === x && _isMemoSame(_cached, _memo)) return _cached
if (_cached && _cached.el && _cached.key === (x) && _isMemoSame(_cached, _memo)) return _cached
const _item = (_openBlock(), _createElementBlock("span", { key: x }, "foobar"))
_item.memo = _memo
return _item
Expand All @@ -53,7 +53,7 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, ({ x, y }, __, ___, _cached) => {
const _memo = ([x, y === _ctx.z])
if (_cached && _cached.el && _cached.key === _ctx.get(x) && _isMemoSame(_cached, _memo)) return _cached
if (_cached && _cached.el && _cached.key === (_ctx.get(x)) && _isMemoSame(_cached, _memo)) return _cached
const _item = (_openBlock(), _createElementBlock("span", {
key: _ctx.get(x)
}, "foobar"))
Expand All @@ -71,7 +71,7 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, ({ x, y }, __, ___, _cached) => {
const _memo = ([x, y === _ctx.z])
if (_cached && _cached.el && _cached.key === x && _isMemoSame(_cached, _memo)) return _cached
if (_cached && _cached.el && _cached.key === (x) && _isMemoSame(_cached, _memo)) return _cached
const _item = (_openBlock(), _createElementBlock("div", { key: x }, [
_createElementVNode("span", null, "foobar")
]))
Expand All @@ -89,7 +89,7 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, ({ x, y }, __, ___, _cached) => {
const _memo = ([x, y === _ctx.z])
if (_cached && _cached.el && _cached.key === _ctx.get(x) && _isMemoSame(_cached, _memo)) return _cached
if (_cached && _cached.el && _cached.key === (_ctx.get(x)) && _isMemoSame(_cached, _memo)) return _cached
const _item = (_openBlock(), _createElementBlock("div", {
key: _ctx.get(x)
}, [
Expand Down
10 changes: 10 additions & 0 deletions packages/compiler-core/__tests__/transforms/vMemo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ describe('compiler: v-memo transform', () => {
).toMatchSnapshot()
})

test('on v-for w/ conditional key expression', () => {
const code = compile(
`<div v-for="{ x, y } in list" :key="x ? x : y" v-memo="[x, y === z]">
<span>foobar</span>
</div>`,
)

expect(code).toContain(`_cached.key === (x ? x : y)`)
})

test('on template v-for', () => {
expect(
compile(
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(
createCompoundExpression([`const _memo = (`, memo.exp!, `)`]),
createCompoundExpression([
`if (_cached && _cached.el`,
...(keyExp ? [` && _cached.key === `, keyExp] : []),
...(keyExp ? [` && _cached.key === (`, keyExp, `)`] : []),
` && ${context.helperString(
IS_MEMO_SAME,
)}(_cached, _memo)) return _cached`,
Expand Down
Loading