Skip to content

Commit

Permalink
refactor: more concise bitwise operations for flag removal (vuejs#7092)
Browse files Browse the repository at this point in the history
  • Loading branch information
花果山大圣 authored and zhangzhonghe committed Apr 12, 2023
1 parent 6c03497 commit 19ea77a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
11 changes: 3 additions & 8 deletions packages/runtime-core/src/components/KeepAlive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,9 @@ function injectToKeepAliveRoot(
}

function resetShapeFlag(vnode: VNode) {
let shapeFlag = vnode.shapeFlag
if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
}
if (shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {
shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE
}
vnode.shapeFlag = shapeFlag
// bitwise operations to remove keep alive flags
vnode.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
vnode.shapeFlag &= ~ShapeFlags.COMPONENT_KEPT_ALIVE
}

function getInnerChild(vnode: VNode) {
Expand Down
10 changes: 3 additions & 7 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,9 @@ export function isSameVNodeType(n1: VNode, n2: VNode): boolean {
hmrDirtyComponents.has(n2.type as ConcreteComponent)
) {
// #7042, ensure the vnode being unmounted during HMR
if (n1.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
n1.shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
}
// #7042, ensure the vnode being mounted as fresh during HMR
if (n2.shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {
n2.shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE
}
// bitwise operations to remove keep alive flags
n1.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
n2.shapeFlag &= ~ShapeFlags.COMPONENT_KEPT_ALIVE
// HMR only: if the component has been hot-updated, force a reload.
return false
}
Expand Down

0 comments on commit 19ea77a

Please sign in to comment.