@@ -66,6 +66,7 @@ import {
66
66
67
67
import {
68
68
REACT_ELEMENT_TYPE ,
69
+ REACT_TRANSITIONAL_ELEMENT_TYPE ,
69
70
REACT_PORTAL_TYPE ,
70
71
REACT_FRAGMENT_TYPE ,
71
72
REACT_STRICT_MODE_TYPE ,
@@ -86,7 +87,19 @@ const REACT_INTERNALS =
86
87
( React : any ) . __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE
87
88
88
89
const ReactCurrentDispatcher =
89
- REACT_INTERNALS && REACT_INTERNALS . ReactCurrentDispatcher
90
+ REACT_INTERNALS . ReactCurrentDispatcher || REACT_INTERNALS
91
+
92
+ const getReactCurrentDispatcher = ( ) => {
93
+ return ReactCurrentDispatcher . current || ReactCurrentDispatcher . H
94
+ }
95
+
96
+ const injectReactCurrentDispatcher = ( newDispatcher ) => {
97
+ if ( ReactCurrentDispatcher . current ) {
98
+ ReactCurrentDispatcher . current = newDispatcher
99
+ } else {
100
+ ReactCurrentDispatcher . H = newDispatcher
101
+ }
102
+ }
90
103
91
104
// In the presence of setImmediate, i.e. on Node, we'll enable the
92
105
// yielding behavior that gives the event loop a chance to continue
@@ -141,7 +154,9 @@ export const visitElement = (
141
154
const providerElement = ( ( element : any ) : ProviderElement )
142
155
// Add provider's value prop to context
143
156
const { value, children } = providerElement . props
144
- setContextValue ( providerElement . type . _context , value )
157
+ const type = ( providerElement . type : any )
158
+ const context = typeof type . _context === 'object' ? type . _context : type
159
+ setContextValue ( context , value )
145
160
146
161
return getChildrenArray ( children )
147
162
}
@@ -221,11 +236,11 @@ const visitLoop = (
221
236
visitor : Visitor ,
222
237
clientRefVisitor : ClientReferenceVisitor
223
238
) : boolean => {
224
- const prevDispatcher = ReactCurrentDispatcher . current
239
+ const prevDispatcher = getReactCurrentDispatcher ( )
225
240
const start = Date . now ( )
226
241
227
242
try {
228
- ReactCurrentDispatcher . current = Dispatcher
243
+ injectReactCurrentDispatcher ( Dispatcher )
229
244
while ( traversalChildren . length > 0 ) {
230
245
const element = traversalChildren [ traversalChildren . length - 1 ] . shift ( )
231
246
if ( element !== undefined ) {
@@ -254,7 +269,7 @@ const visitLoop = (
254
269
queue . unshift ( errorFrame )
255
270
return false
256
271
} finally {
257
- ReactCurrentDispatcher . current = prevDispatcher
272
+ injectReactCurrentDispatcher ( prevDispatcher )
258
273
}
259
274
}
260
275
@@ -341,10 +356,10 @@ export const update = (
341
356
)
342
357
}
343
358
} else {
344
- const prevDispatcher = ReactCurrentDispatcher . current
359
+ const prevDispatcher = getReactCurrentDispatcher ( )
345
360
let children = null
346
361
347
- ReactCurrentDispatcher . current = Dispatcher
362
+ injectReactCurrentDispatcher ( Dispatcher )
348
363
349
364
try {
350
365
if ( frame . kind === 'frame . class ') {
@@ -363,7 +378,7 @@ export const update = (
363
378
queue . unshift ( errorFrame )
364
379
children = null
365
380
} finally {
366
- ReactCurrentDispatcher . current = prevDispatcher
381
+ injectReactCurrentDispatcher ( prevDispatcher )
367
382
}
368
383
369
384
visit ( getChildrenArray ( children ) , queue , visitor , clientRefVisitor )
0 commit comments