@@ -12,12 +12,12 @@ import {isForwardRef, isMemo, ForwardRef} from 'react-is';
1212import describeComponentFrame from './shared/describeComponentFrame' ;
1313import getComponentName from './shared/getComponentName' ;
1414import shallowEqual from './shared/shallowEqual' ;
15- import checkPropTypes from 'prop-types /checkPropTypes' ;
15+ import checkPropTypes from './shared /checkPropTypes' ;
1616import ReactSharedInternals from './shared/ReactSharedInternals' ;
1717import { error } from './shared/consoleWithStackDev' ;
1818import is from './shared/objectIs' ;
1919
20- const { ReactCurrentDispatcher} = ReactSharedInternals ;
20+ const { ReactCurrentDispatcher, ReactDebugCurrentFrame } = ReactSharedInternals ;
2121
2222const RE_RENDER_LIMIT = 25 ;
2323
@@ -503,91 +503,100 @@ See https://fb.me/react-invalid-hook-call for tips about how to debug and fix th
503503 this . _context = getMaskedContext ( elementType . contextTypes , context ) ;
504504
505505 // Inner memo component props aren't currently validated in createElement.
506- if ( isMemo ( element ) && elementType . propTypes ) {
507- currentlyValidatingElement = element ;
508- checkPropTypes (
509- elementType . propTypes ,
510- element . props ,
511- 'prop' ,
512- getComponentName ( elementType ) ,
513- getStackAddendum ,
514- ) ;
506+ let prevGetStack ;
507+ if ( process . env . NODE_ENV !== 'production' ) {
508+ prevGetStack = ReactDebugCurrentFrame . getCurrentStack ;
509+ ReactDebugCurrentFrame . getCurrentStack = getStackAddendum ;
515510 }
516-
517- if ( this . _instance ) {
518- this . _updateClassComponent ( elementType , element , this . _context ) ;
519- } else {
520- if ( shouldConstruct ( elementType ) ) {
521- this . _instance = new elementType (
511+ try {
512+ if ( isMemo ( element ) && elementType . propTypes ) {
513+ currentlyValidatingElement = element ;
514+ checkPropTypes (
515+ elementType . propTypes ,
522516 element . props ,
523- this . _context ,
524- this . _updater ,
517+ 'prop' ,
518+ getComponentName ( elementType ) ,
525519 ) ;
526- if ( typeof elementType . getDerivedStateFromProps === 'function' ) {
527- const partialState = elementType . getDerivedStateFromProps . call (
528- null ,
520+ }
521+
522+ if ( this . _instance ) {
523+ this . _updateClassComponent ( elementType , element , this . _context ) ;
524+ } else {
525+ if ( shouldConstruct ( elementType ) ) {
526+ this . _instance = new elementType (
529527 element . props ,
530- this . _instance . state ,
528+ this . _context ,
529+ this . _updater ,
531530 ) ;
532- if ( partialState != null ) {
533- this . _instance . state = Object . assign (
534- { } ,
531+ if ( typeof elementType . getDerivedStateFromProps === 'function' ) {
532+ const partialState = elementType . getDerivedStateFromProps . call (
533+ null ,
534+ element . props ,
535535 this . _instance . state ,
536- partialState ,
537536 ) ;
537+ if ( partialState != null ) {
538+ this . _instance . state = Object . assign (
539+ { } ,
540+ this . _instance . state ,
541+ partialState ,
542+ ) ;
543+ }
538544 }
539- }
540545
541- if ( elementType . contextTypes ) {
542- currentlyValidatingElement = element ;
543- checkPropTypes (
544- elementType . contextTypes ,
545- this . _context ,
546- 'context' ,
547- getName ( elementType , this . _instance ) ,
548- getStackAddendum ,
549- ) ;
546+ if ( elementType . contextTypes ) {
547+ currentlyValidatingElement = element ;
548+ checkPropTypes (
549+ elementType . contextTypes ,
550+ this . _context ,
551+ 'context' ,
552+ getName ( elementType , this . _instance ) ,
553+ ) ;
550554
551- currentlyValidatingElement = null ;
552- }
555+ currentlyValidatingElement = null ;
556+ }
553557
554- this . _mountClassComponent ( elementType , element , this . _context ) ;
555- } else {
556- let shouldRender = true ;
557- if ( isMemo ( element ) && previousElement !== null ) {
558- // This is a Memo component that is being re-rendered.
559- const compare = element . type . compare || shallowEqual ;
560- if ( compare ( previousElement . props , element . props ) ) {
561- shouldRender = false ;
558+ this . _mountClassComponent ( elementType , element , this . _context ) ;
559+ } else {
560+ let shouldRender = true ;
561+ if ( isMemo ( element ) && previousElement !== null ) {
562+ // This is a Memo component that is being re-rendered.
563+ const compare = element . type . compare || shallowEqual ;
564+ if ( compare ( previousElement . props , element . props ) ) {
565+ shouldRender = false ;
566+ }
562567 }
563- }
564- if ( shouldRender ) {
565- const prevDispatcher = ReactCurrentDispatcher . current ;
566- ReactCurrentDispatcher . current = this . _dispatcher ;
567- try {
568- // elementType could still be a ForwardRef if it was
569- // nested inside Memo.
570- if ( elementType . $$typeof === ForwardRef ) {
571- if ( ! ( typeof elementType . render === 'function' ) ) {
572- throw Error (
573- `forwardRef requires a render function but was given ${ typeof elementType . render } .` ,
568+ if ( shouldRender ) {
569+ const prevDispatcher = ReactCurrentDispatcher . current ;
570+ ReactCurrentDispatcher . current = this . _dispatcher ;
571+ try {
572+ // elementType could still be a ForwardRef if it was
573+ // nested inside Memo.
574+ if ( elementType . $$typeof === ForwardRef ) {
575+ if ( ! ( typeof elementType . render === 'function' ) ) {
576+ throw Error (
577+ `forwardRef requires a render function but was given ${ typeof elementType . render } .` ,
578+ ) ;
579+ }
580+ this . _rendered = elementType . render . call (
581+ undefined ,
582+ element . props ,
583+ element . ref ,
574584 ) ;
585+ } else {
586+ this . _rendered = elementType ( element . props , this . _context ) ;
575587 }
576- this . _rendered = elementType . render . call (
577- undefined ,
578- element . props ,
579- element . ref ,
580- ) ;
581- } else {
582- this . _rendered = elementType ( element . props , this . _context ) ;
588+ } finally {
589+ ReactCurrentDispatcher . current = prevDispatcher ;
583590 }
584- } finally {
585- ReactCurrentDispatcher . current = prevDispatcher ;
591+ this . _finishHooks ( element , context ) ;
586592 }
587- this . _finishHooks ( element , context ) ;
588593 }
589594 }
590- }
595+ } finally {
596+ if ( process . env . NODE_ENV !== 'production' ) {
597+ ReactDebugCurrentFrame . getCurrentStack = prevGetStack ;
598+ }
599+ }
591600
592601 this . _rendering = false ;
593602 this . _updater . _invokeCallbacks ( ) ;
0 commit comments