@@ -75,6 +75,7 @@ const toArray = ((React.Children.toArray: any): toArrayType);
75
75
// Each stack is an array of frames which may contain nested stacks of elements.
76
76
let currentDebugStacks = [];
77
77
78
+ let ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
78
79
let ReactDebugCurrentFrame;
79
80
let prevGetCurrentStackImpl = null;
80
81
let getCurrentServerStackImpl = () => '';
@@ -85,6 +86,15 @@ let pushCurrentDebugStack = (stack: Array<Frame>) => {};
85
86
let pushElementToDebugStack = (element: ReactElement) => {};
86
87
let popCurrentDebugStack = () => {};
87
88
89
+ let Dispatcher = {
90
+ readContext<T>(
91
+ context: ReactContext<T>,
92
+ observedBits: void | number | boolean,
93
+ ): T {
94
+ return context._currentValue;
95
+ },
96
+ };
97
+
88
98
if (__DEV__) {
89
99
ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
90
100
@@ -787,49 +797,54 @@ class ReactDOMServerRenderer {
787
797
return null;
788
798
}
789
799
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;
802
807
}
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;
813
827
}
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.
823
841
out += this.render(child, frame.context, frame.domNamespace);
824
- } finally {
825
- popCurrentDebugStack ( ) ;
826
842
}
827
- } else {
828
- // Be careful! Make sure this matches the DEV path above.
829
- out += this . render ( child , frame . context , frame . domNamespace ) ;
830
843
}
844
+ return out;
845
+ } finally {
846
+ ReactCurrentOwner.currentDispatcher = null;
831
847
}
832
- return out ;
833
848
}
834
849
835
850
render(
0 commit comments