isCompatibleFamilyForHotReloading() — react Function Reference
Architecture documentation for the isCompatibleFamilyForHotReloading() function in ReactFiberHotReloading.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD a0fe843c_1660_fd60_7942_2fc8992075f7["isCompatibleFamilyForHotReloading()"] da68ece0_17b1_3c98_d393_5c830eacd9b2["ReactFiberHotReloading.js"] a0fe843c_1660_fd60_7942_2fc8992075f7 -->|defined in| da68ece0_17b1_3c98_d393_5c830eacd9b2 style a0fe843c_1660_fd60_7942_2fc8992075f7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/react-reconciler/src/ReactFiberHotReloading.js lines 124–204
export function isCompatibleFamilyForHotReloading(
fiber: Fiber,
element: ReactElement,
): boolean {
if (__DEV__) {
if (resolveFamily === null) {
// Hot reloading is disabled.
return false;
}
const prevType = fiber.elementType;
const nextType = element.type;
// If we got here, we know types aren't === equal.
let needsCompareFamilies = false;
const $$typeofNextType =
typeof nextType === 'object' && nextType !== null
? nextType.$$typeof
: null;
switch (fiber.tag) {
case ClassComponent: {
if (typeof nextType === 'function') {
needsCompareFamilies = true;
}
break;
}
case FunctionComponent: {
if (typeof nextType === 'function') {
needsCompareFamilies = true;
} else if ($$typeofNextType === REACT_LAZY_TYPE) {
// We don't know the inner type yet.
// We're going to assume that the lazy inner type is stable,
// and so it is sufficient to avoid reconciling it away.
// We're not going to unwrap or actually use the new lazy type.
needsCompareFamilies = true;
}
break;
}
case ForwardRef: {
if ($$typeofNextType === REACT_FORWARD_REF_TYPE) {
needsCompareFamilies = true;
} else if ($$typeofNextType === REACT_LAZY_TYPE) {
needsCompareFamilies = true;
}
break;
}
case MemoComponent:
case SimpleMemoComponent: {
if ($$typeofNextType === REACT_MEMO_TYPE) {
// TODO: if it was but can no longer be simple,
// we shouldn't set this.
needsCompareFamilies = true;
} else if ($$typeofNextType === REACT_LAZY_TYPE) {
needsCompareFamilies = true;
}
break;
}
default:
return false;
}
// Check if both types have a family and it's the same one.
if (needsCompareFamilies) {
// Note: memo() and forwardRef() we'll compare outer rather than inner type.
// This means both of them need to be registered to preserve state.
// If we unwrapped and compared the inner types for wrappers instead,
// then we would risk falsely saying two separate memo(Foo)
// calls are equivalent because they wrap the same Foo function.
const prevFamily = resolveFamily(prevType);
// $FlowFixMe[not-a-function] found when upgrading Flow
if (prevFamily !== undefined && prevFamily === resolveFamily(nextType)) {
return true;
}
}
return false;
} else {
return false;
}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does isCompatibleFamilyForHotReloading() do?
isCompatibleFamilyForHotReloading() is a function in the react codebase, defined in packages/react-reconciler/src/ReactFiberHotReloading.js.
Where is isCompatibleFamilyForHotReloading() defined?
isCompatibleFamilyForHotReloading() is defined in packages/react-reconciler/src/ReactFiberHotReloading.js at line 124.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free