Skip to content

Commit

Permalink
wip: save
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Jan 15, 2025
1 parent cf88048 commit 783d60a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.tableData, (data, _key, ___, _cached) => {
const _memo = (_ctx.getLetter(data))
if (_cached && _cached.key === _ctx.getId(data) && _isMemoSame(_cached, _memo)) return _cached
if (_cached && _cached.el && _cached.key === _ctx.getId(data) && _isMemoSame(_cached, _memo)) return _cached
const _item = (_openBlock(), _createElementBlock("span", {
key: _ctx.getId(data)
}))
_item.memo = _memo
_item.cacheIndex = _key
_item.cacheIndex = [0, _key]
return _item
}, _cache, 0), 128 /* KEYED_FRAGMENT */))
]))
Expand Down Expand Up @@ -56,10 +56,10 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, ({ x, y }, _key, ___, _cached) => {
const _memo = ([x, y === _ctx.z])
if (_cached && _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
_item.cacheIndex = _key
_item.cacheIndex = [0, _key]
return _item
}, _cache, 0), 128 /* KEYED_FRAGMENT */))
]))
Expand All @@ -73,12 +73,12 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", null, [
(_openBlock(true), _createElementBlock(_Fragment, null, _renderList(_ctx.list, ({ x, y }, _key, ___, _cached) => {
const _memo = ([x, y === _ctx.z])
if (_cached && _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")
]))
_item.memo = _memo
_item.cacheIndex = _key
_item.cacheIndex = [0, _key]
return _item
}, _cache, 0), 128 /* KEYED_FRAGMENT */))
]))
Expand Down
6 changes: 4 additions & 2 deletions packages/compiler-core/src/transforms/vFor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,17 @@ export const transformFor: NodeTransform = createStructuralDirectiveTransform(
loop.body = createBlockStatement([
createCompoundExpression([`const _memo = (`, memo.exp!, `)`]),
createCompoundExpression([
`if (_cached`,
`if (_cached && _cached.el`,
...(keyExp ? [` && _cached.key === `, keyExp] : []),
` && ${context.helperString(
IS_MEMO_SAME,
)}(_cached, _memo)) return _cached`,
]),
createCompoundExpression([`const _item = `, childBlock as any]),
createSimpleExpression(`_item.memo = _memo`),
createSimpleExpression(`_item.cacheIndex = _key`),
createSimpleExpression(
`_item.cacheIndex = [${context.cached.length}, _key]`,
),
createSimpleExpression(`return _item`),
])
renderExp.arguments.push(
Expand Down
10 changes: 9 additions & 1 deletion packages/runtime-core/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,15 @@ function baseCreateRenderer(

// #6593 should clean memo cache when unmount
if (cacheIndex != null) {
parentComponent!.renderCache[cacheIndex] = undefined
if (isArray(cacheIndex)) {
const [parentIndex, itemIndex] = cacheIndex
const parentCache = parentComponent!.renderCache[
parentIndex
]! as unknown as VNode[]
parentCache[itemIndex].el = null
} else {
parentComponent!.renderCache[cacheIndex] = undefined
}
}

if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@ export interface VNode<
memo?: any[]
/**
* @internal index for cleaning v-memo cache
* cacheIndex will be an array when vnode in vFor
*/
cacheIndex?: number
cacheIndex?: number | number[]
/**
* @internal __COMPAT__ only
*/
Expand Down

0 comments on commit 783d60a

Please sign in to comment.