@@ -22,12 +22,7 @@ const {
2222 ReactCurrentDispatcher
2323} = ( React : any ) . __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
2424
25- const visit = ( children : AbstractElement [ ] , queue : Frame [ ] , visitor : Visitor ) => {
26- const prevDispatcher = ReactCurrentDispatcher . current
27- ReactCurrentDispatcher . current = Dispatcher
28- visitChildren ( children , queue , visitor )
29- ReactCurrentDispatcher . current = prevDispatcher
30- }
25+ let prevDispatcher = ReactCurrentDispatcher . current
3126
3227const flushFrames = ( queue : Frame [ ] , visitor : Visitor ) : Promise < void > => {
3328 if ( queue . length === 0 ) {
@@ -37,6 +32,9 @@ const flushFrames = (queue: Frame[], visitor: Visitor): Promise<void> => {
3732 const frame = queue . shift ( )
3833
3934 return frame . thenable . then ( ( ) => {
35+ prevDispatcher = ReactCurrentDispatcher . current
36+ ReactCurrentDispatcher . current = Dispatcher
37+
4038 let children = [ ]
4139 if ( frame . kind === 'frame.class' ) {
4240 children = getChildrenArray ( updateClassComponent ( queue , frame ) )
@@ -46,7 +44,9 @@ const flushFrames = (queue: Frame[], visitor: Visitor): Promise<void> => {
4644 children = getChildrenArray ( updateLazyComponent ( queue , frame ) )
4745 }
4846
49- visit ( children , queue , visitor )
47+ visitChildren ( children , queue , visitor )
48+ ReactCurrentDispatcher . current = prevDispatcher
49+
5050 return flushFrames ( queue , visitor )
5151 } )
5252}
@@ -59,9 +59,13 @@ const renderPrepass = (element: Node, visitor?: Visitor): Promise<void> => {
5959 clearCurrentContextMap ( )
6060
6161 try {
62- visit ( getChildrenArray ( element ) , queue , fn )
62+ prevDispatcher = ReactCurrentDispatcher . current
63+ ReactCurrentDispatcher . current = Dispatcher
64+ visitChildren ( getChildrenArray ( element ) , queue , fn )
6365 } catch ( error ) {
6466 return Promise . reject ( error )
67+ } finally {
68+ ReactCurrentDispatcher . current = prevDispatcher
6569 }
6670
6771 return flushFrames ( queue , fn )
0 commit comments