( prevVNode: VNode, nextVNode: VNode, optimized?: boolean, )
| 369 | } |
| 370 | |
| 371 | export function shouldUpdateComponent( |
| 372 | prevVNode: VNode, |
| 373 | nextVNode: VNode, |
| 374 | optimized?: boolean, |
| 375 | ): boolean { |
| 376 | const { props: prevProps, children: prevChildren, component } = prevVNode |
| 377 | const { props: nextProps, children: nextChildren, patchFlag } = nextVNode |
| 378 | const emits = component!.emitsOptions |
| 379 | |
| 380 | // Parent component's render function was hot-updated. Since this may have |
| 381 | // caused the child component's slots content to have changed, we need to |
| 382 | // force the child to update as well. |
| 383 | if (__DEV__ && (prevChildren || nextChildren) && isHmrUpdating) { |
| 384 | return true |
| 385 | } |
| 386 | |
| 387 | // force child update for runtime directive or transition on component vnode. |
| 388 | if (nextVNode.dirs || nextVNode.transition) { |
| 389 | return true |
| 390 | } |
| 391 | |
| 392 | if (optimized && patchFlag >= 0) { |
| 393 | if (patchFlag & PatchFlags.DYNAMIC_SLOTS) { |
| 394 | // slot content that references values that might have changed, |
| 395 | // e.g. in a v-for |
| 396 | return true |
| 397 | } |
| 398 | if (patchFlag & PatchFlags.FULL_PROPS) { |
| 399 | if (!prevProps) { |
| 400 | return !!nextProps |
| 401 | } |
| 402 | // presence of this flag indicates props are always non-null |
| 403 | return hasPropsChanged(prevProps, nextProps!, emits) |
| 404 | } else if (patchFlag & PatchFlags.PROPS) { |
| 405 | const dynamicProps = nextVNode.dynamicProps! |
| 406 | for (let i = 0; i < dynamicProps.length; i++) { |
| 407 | const key = dynamicProps[i] |
| 408 | if ( |
| 409 | hasPropValueChanged(nextProps!, prevProps!, key) && |
| 410 | !isEmitListener(emits, key) |
| 411 | ) { |
| 412 | return true |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | } else { |
| 417 | // this path is only taken by manually written render functions |
| 418 | // so presence of any children leads to a forced update |
| 419 | if (prevChildren || nextChildren) { |
| 420 | if (!nextChildren || !(nextChildren as any).$stable) { |
| 421 | return true |
| 422 | } |
| 423 | } |
| 424 | if (prevProps === nextProps) { |
| 425 | return false |
| 426 | } |
| 427 | if (!prevProps) { |
| 428 | return !!nextProps |
no test coverage detected