@@ -75,6 +75,7 @@ const toArray = ((React.Children.toArray: any): toArrayType);
7575// Each stack is an array of frames which may contain nested stacks of elements.
7676let currentDebugStacks = [];
7777
78+ let ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
7879let ReactDebugCurrentFrame;
7980let prevGetCurrentStackImpl = null;
8081let getCurrentServerStackImpl = () => '';
@@ -85,6 +86,15 @@ let pushCurrentDebugStack = (stack: Array<Frame>) => {};
8586let pushElementToDebugStack = (element: ReactElement) => {};
8687let popCurrentDebugStack = () => {};
8788
89+ let Dispatcher = {
90+ readContext<T>(
91+ context: ReactContext<T>,
92+ observedBits: void | number | boolean,
93+ ): T {
94+ return context._currentValue;
95+ },
96+ };
97+
8898if (__DEV__) {
8999 ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
90100
@@ -787,49 +797,54 @@ class ReactDOMServerRenderer {
787797 return null;
788798 }
789799
790- let out = '';
791- while ( out . length < bytes ) {
792- if ( this . stack . length === 0 ) {
793- this . exhausted = true ;
794- break ;
795- }
796- const frame : Frame = this . stack [ this . stack . length - 1 ] ;
797- if ( frame . childIndex >= frame . children . length ) {
798- const footer = frame . footer ;
799- out += footer ;
800- if ( footer !== '' ) {
801- this . previousWasTextNode = false ;
800+ ReactCurrentOwner.currentDispatcher = Dispatcher;
801+ try {
802+ let out = '';
803+ while (out.length < bytes) {
804+ if (this.stack.length === 0) {
805+ this.exhausted = true;
806+ break;
802807 }
803- this . stack . pop ( ) ;
804- if ( frame . type === 'select' ) {
805- this . currentSelectValue = null ;
806- } else if (
807- frame . type != null &&
808- frame . type . type != null &&
809- frame . type . type . $$typeof === REACT_PROVIDER_TYPE
810- ) {
811- const provider : ReactProvider < any > = ( frame . type : any ) ;
812- this . popProvider ( provider ) ;
808+ const frame: Frame = this.stack[this.stack.length - 1];
809+ if (frame.childIndex >= frame.children.length) {
810+ const footer = frame.footer;
811+ out += footer;
812+ if (footer !== '') {
813+ this.previousWasTextNode = false;
814+ }
815+ this.stack.pop();
816+ if (frame.type === 'select') {
817+ this.currentSelectValue = null;
818+ } else if (
819+ frame.type != null &&
820+ frame.type.type != null &&
821+ frame.type.type.$$typeof === REACT_PROVIDER_TYPE
822+ ) {
823+ const provider: ReactProvider<any> = (frame.type: any);
824+ this.popProvider(provider);
825+ }
826+ continue;
813827 }
814- continue ;
815- }
816- const child = frame . children [ frame . childIndex ++ ] ;
817- if ( __DEV__ ) {
818- pushCurrentDebugStack ( this . stack ) ;
819- // We're starting work on this frame, so reset its inner stack.
820- ( ( frame : any ) : FrameDev ) . debugElementStack . length = 0 ;
821- try {
822- // Be careful! Make sure this matches the PROD path below.
828+ const child = frame.children[frame.childIndex++];
829+ if (__DEV__) {
830+ pushCurrentDebugStack(this.stack);
831+ // We're starting work on this frame, so reset its inner stack.
832+ ((frame: any): FrameDev).debugElementStack.length = 0;
833+ try {
834+ // Be careful! Make sure this matches the PROD path below.
835+ out += this.render(child, frame.context, frame.domNamespace);
836+ } finally {
837+ popCurrentDebugStack();
838+ }
839+ } else {
840+ // Be careful! Make sure this matches the DEV path above.
823841 out += this.render(child, frame.context, frame.domNamespace);
824- } finally {
825- popCurrentDebugStack ( ) ;
826842 }
827- } else {
828- // Be careful! Make sure this matches the DEV path above.
829- out += this . render ( child , frame . context , frame . domNamespace ) ;
830843 }
844+ return out;
845+ } finally {
846+ ReactCurrentOwner.currentDispatcher = null;
831847 }
832- return out ;
833848 }
834849
835850 render(
0 commit comments