@@ -352,21 +352,6 @@ function checkClassInstance(workInProgress: Fiber, ctor: any, newProps: any) {
352352 ) ;
353353 }
354354
355- if (
356- ctor . contextType &&
357- typeof ctor . contextType . unstable_read !== 'function' &&
358- ! didWarnAboutInvalidateContextType . has ( ctor )
359- ) {
360- didWarnAboutInvalidateContextType . add ( ctor ) ;
361- warningWithoutStack (
362- false ,
363- '%s defines an invalid contextType. ' +
364- 'contextType should point to the Context object returned by React.createContext(). ' +
365- 'Did you accidentally pass the Context.Provider instead?' ,
366- name ,
367- ) ;
368- }
369-
370355 const noComponentShouldUpdate =
371356 typeof instance . componentShouldUpdate !== 'function' ;
372357 warningWithoutStack (
@@ -520,11 +505,23 @@ function constructClassInstance(
520505 let unmaskedContext = emptyContextObject ;
521506 let context = null ;
522507 const contextType = ctor . contextType ;
523- if (
524- typeof contextType === 'object' &&
525- contextType !== null &&
526- typeof contextType . unstable_read === 'function'
527- ) {
508+ if ( typeof contextType === 'object' && contextType !== null ) {
509+ if ( __DEV__ ) {
510+ if (
511+ typeof contextType . unstable_read !== 'function' &&
512+ ! didWarnAboutInvalidateContextType . has ( ctor )
513+ ) {
514+ didWarnAboutInvalidateContextType . add ( ctor ) ;
515+ warningWithoutStack (
516+ false ,
517+ '%s defines an invalid contextType. ' +
518+ 'contextType should point to the Context object returned by React.createContext(). ' +
519+ 'Did you accidentally pass the Context.Provider instead?' ,
520+ getComponentName ( ctor ) || 'Component' ,
521+ ) ;
522+ }
523+ }
524+
528525 context = ( contextType : any ) . unstable_read ( ) ;
529526 } else {
530527 unmaskedContext = getUnmaskedContext ( workInProgress , ctor , true ) ;
@@ -727,11 +724,7 @@ function mountClassInstance(
727724 instance . refs = emptyRefsObject ;
728725
729726 const contextType = ctor . contextType ;
730- if (
731- typeof contextType === 'object' &&
732- contextType !== null &&
733- typeof contextType . unstable_read === 'function'
734- ) {
727+ if ( typeof contextType === 'object' && contextType !== null ) {
735728 instance . context = ( contextType : any ) . unstable_read ( ) ;
736729 } else {
737730 const unmaskedContext = getUnmaskedContext ( workInProgress , ctor , true ) ;
@@ -839,11 +832,7 @@ function resumeMountClassInstance(
839832 const oldContext = instance . context ;
840833 const contextType = ctor . contextType ;
841834 let nextContext ;
842- if (
843- typeof contextType === 'object' &&
844- contextType !== null &&
845- typeof contextType . unstable_read === 'function'
846- ) {
835+ if ( typeof contextType === 'object' && contextType !== null ) {
847836 nextContext = ( contextType : any ) . unstable_read ( ) ;
848837 } else {
849838 const nextLegacyUnmaskedContext = getUnmaskedContext (
@@ -989,11 +978,7 @@ function updateClassInstance(
989978 const oldContext = instance . context ;
990979 const contextType = ctor . contextType ;
991980 let nextContext ;
992- if (
993- typeof contextType === 'object' &&
994- contextType !== null &&
995- typeof contextType . unstable_read === 'function'
996- ) {
981+ if ( typeof contextType === 'object' && contextType !== null ) {
997982 nextContext = ( contextType : any ) . unstable_read ( ) ;
998983 } else {
999984 const nextUnmaskedContext = getUnmaskedContext ( workInProgress , ctor , true ) ;
0 commit comments