MCPcopy
hub / github.com/vuejs/core / shouldUpdateComponent

Function shouldUpdateComponent

packages/runtime-core/src/componentRenderUtils.ts:371–437  ·  view source on GitHub ↗
(
  prevVNode: VNode,
  nextVNode: VNode,
  optimized?: boolean,
)

Source from the content-addressed store, hash-verified

369}
370
371export 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

Callers 1

updateComponentFunction · 0.90

Calls 3

isEmitListenerFunction · 0.90
hasPropsChangedFunction · 0.85
hasPropValueChangedFunction · 0.85

Tested by

no test coverage detected