@@ -318,6 +318,12 @@ export const SelectiveHydrationException: mixed = new Error(
318318
319319let didReceiveUpdate : boolean = false ;
320320
321+ // Map from SimpleMemoComponent function to compare a.k.a. arePropsEqual function.
322+ const simpleMemoComponentToCompare = new WeakMap <
323+ Function ,
324+ ( objA : mixed , objB : mixed ) => boolean ,
325+ > ( ) ;
326+
321327let didWarnAboutBadClass ;
322328let didWarnAboutContextTypeOnFunctionComponent ;
323329let didWarnAboutContextTypes ;
@@ -478,16 +484,18 @@ function updateMemoComponent(
478484) : null | Fiber {
479485 if ( current === null ) {
480486 const type = Component . type ;
481- if ( isSimpleFunctionComponent ( type ) && Component . compare === null ) {
487+ if ( isSimpleFunctionComponent ( type ) ) {
482488 let resolvedType = type ;
483489 if ( __DEV__ ) {
484490 resolvedType = resolveFunctionForHotReloading ( type ) ;
485491 }
486492 // If this is a plain function component without default props,
487- // and with only the default shallow comparison, we upgrade it
488- // to a SimpleMemoComponent to allow fast path updates.
493+ // we upgrade it to a SimpleMemoComponent to allow fast path updates.
489494 workInProgress . tag = SimpleMemoComponent ;
490495 workInProgress . type = resolvedType ;
496+ if ( Component . compare ) {
497+ simpleMemoComponentToCompare . set ( resolvedType , Component . compare ) ;
498+ }
491499 if ( __DEV__ ) {
492500 validateFunctionComponentInDev ( workInProgress , type ) ;
493501 }
@@ -548,9 +556,10 @@ function updateSimpleMemoComponent(
548556 // hasn't yet mounted. This happens when the inner render suspends.
549557 // We'll need to figure out if this is fine or can cause issues.
550558 if ( current !== null ) {
559+ const compare = simpleMemoComponentToCompare . get ( Component ) ?? shallowEqual ;
551560 const prevProps = current . memoizedProps ;
552561 if (
553- shallowEqual ( prevProps , nextProps ) &&
562+ compare ( prevProps , nextProps ) &&
554563 current . ref === workInProgress . ref &&
555564 // Prevent bailout if the implementation changed due to hot reload.
556565 ( __DEV__ ? workInProgress . type === current . type : true )
0 commit comments