fix(v-memo): ensure track block when returning cached vnode (#4270)
fix #4253
This commit is contained in:
@@ -7,11 +7,7 @@ export function withMemo(
|
||||
index: number
|
||||
) {
|
||||
const cached = cache[index] as VNode | undefined
|
||||
if (cached && isMemoSame(cached.memo!, memo)) {
|
||||
// make sure to let parent block track it when returning cached
|
||||
if (isBlockTreeEnabled > 0 && currentBlock) {
|
||||
currentBlock.push(cached)
|
||||
}
|
||||
if (cached && isMemoSame(cached, memo)) {
|
||||
return cached
|
||||
}
|
||||
const ret = render()
|
||||
@@ -19,11 +15,17 @@ export function withMemo(
|
||||
return (cache[index] = ret)
|
||||
}
|
||||
|
||||
export function isMemoSame(prev: any[], next: any[]) {
|
||||
export function isMemoSame(cached: VNode, memo: any[]) {
|
||||
const prev: any[] = cached.memo!
|
||||
for (let i = 0; i < prev.length; i++) {
|
||||
if (prev[i] !== next[i]) {
|
||||
if (prev[i] !== memo[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// make sure to let parent block track it when returning cached
|
||||
if (isBlockTreeEnabled > 0 && currentBlock) {
|
||||
currentBlock.push(cached)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user