Skip to content

Commit 4798a9f

Browse files
authored
refactor: more concise bitwise operations for flag removal (#7092)
1 parent 845efbb commit 4798a9f

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

packages/runtime-core/src/components/KeepAlive.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -424,14 +424,9 @@ function injectToKeepAliveRoot(
424424
}
425425

426426
function resetShapeFlag(vnode: VNode) {
427-
let shapeFlag = vnode.shapeFlag
428-
if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
429-
shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
430-
}
431-
if (shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {
432-
shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE
433-
}
434-
vnode.shapeFlag = shapeFlag
427+
// bitwise operations to remove keep alive flags
428+
vnode.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
429+
vnode.shapeFlag &= ~ShapeFlags.COMPONENT_KEPT_ALIVE
435430
}
436431

437432
function getInnerChild(vnode: VNode) {

packages/runtime-core/src/vnode.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,9 @@ export function isSameVNodeType(n1: VNode, n2: VNode): boolean {
358358
hmrDirtyComponents.has(n2.type as ConcreteComponent)
359359
) {
360360
// #7042, ensure the vnode being unmounted during HMR
361-
if (n1.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
362-
n1.shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
363-
}
364-
// #7042, ensure the vnode being mounted as fresh during HMR
365-
if (n2.shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {
366-
n2.shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE
367-
}
361+
// bitwise operations to remove keep alive flags
362+
n1.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
363+
n2.shapeFlag &= ~ShapeFlags.COMPONENT_KEPT_ALIVE
368364
// HMR only: if the component has been hot-updated, force a reload.
369365
return false
370366
}

0 commit comments

Comments
 (0)