updateHostComponent
typescript
function updateHostComponent(current, workInProgress, renderExpirationTime) {
const type = workInProgress.type;
const nextProps = workInProgress.pendingProps;
const prevProps = current !== null ? current.memoizedProps : null;
let nextChildren = nextProps.children;
// 判断否是纯文本或者 dangerouslySetInnerHTML,也就是里面的内容不需要React渲染
const isDirectTextChild = shouldSetTextContent(type, nextProps);
if (isDirectTextChild) {
nextChildren = null;
} else if (prevProps !== null && shouldSetTextContent(type, prevProps)) {
// 老的props不是空,并且老的节点是文本节点或者 dangerouslySetInnerHTML
// 是的话,需要打上内容重置的tag,
workInProgress.effectTag |= ContentReset;
}
if (
renderExpirationTime !== Never &&
workInProgress.mode & ConcurrentMode &&
shouldDeprioritizeSubtree(type, nextProps)
) {
// 如果ConcurrentMode下,有节点设置了hidden属性,那么当前节点以及以下
// 永远不会被React渲染
workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
return null;
}
reconcileChildren(
current,
workInProgress,
nextChildren,
renderExpirationTime,
);
return workInProgress.child;
}shouldSetTextContent
typescript
export function shouldSetTextContent(type: string, props: Props): boolean {
return (
type === 'textarea' ||
type === 'option' ||
type === 'noscript' ||
typeof props.children === 'string' ||
typeof props.children === 'number' ||
(typeof props.dangerouslySetInnerHTML === 'object' &&
props.dangerouslySetInnerHTML !== null &&
props.dangerouslySetInnerHTML.__html != null)
);
}shouldDeprioritizeSubtree
typescript
export function shouldDeprioritizeSubtree(type: string, props: Props): boolean {
return !!props.hidden;
}updateHostText
typescript
function updateHostText(current, workInProgress) {
if (current === null) {
tryToClaimNextHydratableInstance(workInProgress);
}
// Nothing to do here. This is terminal. We'll do the completion step
// immediately after.
return null;
}