@@ -66,6 +66,7 @@ import {
6666
6767import {
6868 REACT_ELEMENT_TYPE ,
69+ REACT_TRANSITIONAL_ELEMENT_TYPE ,
6970 REACT_PORTAL_TYPE ,
7071 REACT_FRAGMENT_TYPE ,
7172 REACT_STRICT_MODE_TYPE ,
@@ -76,7 +77,8 @@ import {
7677 REACT_FORWARD_REF_TYPE ,
7778 REACT_SUSPENSE_TYPE ,
7879 REACT_MEMO_TYPE ,
79- REACT_LAZY_TYPE
80+ REACT_LAZY_TYPE ,
81+ REACT_CONSUMER_TYPE
8082} from './symbols'
8183
8284import { isClientReference } from './utils'
@@ -86,7 +88,19 @@ const REACT_INTERNALS =
8688 ( React : any ) . __CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE
8789
8890const ReactCurrentDispatcher =
89- REACT_INTERNALS && REACT_INTERNALS . ReactCurrentDispatcher
91+ REACT_INTERNALS . ReactCurrentDispatcher || REACT_INTERNALS
92+
93+ const getReactCurrentDispatcher = ( ) => {
94+ return ReactCurrentDispatcher . current || ReactCurrentDispatcher . H
95+ }
96+
97+ const injectReactCurrentDispatcher = ( newDispatcher ) => {
98+ if ( ReactCurrentDispatcher . current ) {
99+ ReactCurrentDispatcher . current = newDispatcher
100+ } else {
101+ ReactCurrentDispatcher . H = newDispatcher
102+ }
103+ }
90104
91105// In the presence of setImmediate, i.e. on Node, we'll enable the
92106// yielding behavior that gives the event loop a chance to continue
@@ -141,12 +155,14 @@ export const visitElement = (
141155 const providerElement = ( ( element : any ) : ProviderElement )
142156 // Add provider's value prop to context
143157 const { value, children } = providerElement . props
144- setContextValue ( providerElement . type . _context , value )
158+ const type = ( providerElement . type : any )
159+ const context = typeof type . _context === 'object' ? type . _context : type
160+ setContextValue ( context , value )
145161
146162 return getChildrenArray ( children )
147163 }
148164
149- case REACT_CONTEXT_TYPE : {
165+ case REACT_CONSUMER_TYPE : {
150166 const consumerElement = ( ( element : any ) : ConsumerElement )
151167 const { children } = consumerElement . props
152168
@@ -221,11 +237,11 @@ const visitLoop = (
221237 visitor : Visitor ,
222238 clientRefVisitor : ClientReferenceVisitor
223239) : boolean => {
224- const prevDispatcher = ReactCurrentDispatcher . current
240+ const prevDispatcher = getReactCurrentDispatcher ( )
225241 const start = Date . now ( )
226242
227243 try {
228- ReactCurrentDispatcher . current = Dispatcher
244+ injectReactCurrentDispatcher ( Dispatcher )
229245 while ( traversalChildren . length > 0 ) {
230246 const element = traversalChildren [ traversalChildren . length - 1 ] . shift ( )
231247 if ( element !== undefined ) {
@@ -254,7 +270,7 @@ const visitLoop = (
254270 queue . unshift ( errorFrame )
255271 return false
256272 } finally {
257- ReactCurrentDispatcher . current = prevDispatcher
273+ injectReactCurrentDispatcher ( prevDispatcher )
258274 }
259275}
260276
@@ -341,10 +357,10 @@ export const update = (
341357 )
342358 }
343359 } else {
344- const prevDispatcher = ReactCurrentDispatcher . current
360+ const prevDispatcher = getReactCurrentDispatcher ( )
345361 let children = null
346362
347- ReactCurrentDispatcher . current = Dispatcher
363+ injectReactCurrentDispatcher ( Dispatcher )
348364
349365 try {
350366 if ( frame . kind === 'frame . class ') {
@@ -363,7 +379,7 @@ export const update = (
363379 queue . unshift ( errorFrame )
364380 children = null
365381 } finally {
366- ReactCurrentDispatcher . current = prevDispatcher
382+ injectReactCurrentDispatcher ( prevDispatcher )
367383 }
368384
369385 visit ( getChildrenArray ( children ) , queue , visitor , clientRefVisitor )
0 commit comments