@@ -14,33 +14,26 @@ import type {Container, HostContext} from './ReactFiberHostConfig';
14
14
import { getChildHostContext , getRootHostContext } from './ReactFiberHostConfig' ;
15
15
import { createCursor , push , pop } from './ReactFiberStack.new' ;
16
16
17
- declare class NoContextT { }
18
- const NO_CONTEXT : NoContextT = ( { } : any ) ;
19
-
20
- const contextStackCursor : StackCursor < HostContext | NoContextT > = createCursor (
21
- NO_CONTEXT ,
22
- ) ;
23
- const contextFiberStackCursor : StackCursor < Fiber | NoContextT > = createCursor (
24
- NO_CONTEXT ,
17
+ const contextStackCursor : StackCursor < HostContext | null > = createCursor ( null ) ;
18
+ const contextFiberStackCursor : StackCursor < Fiber | null > = createCursor ( null ) ;
19
+ const rootInstanceStackCursor : StackCursor < Container | null > = createCursor (
20
+ null ,
25
21
) ;
26
- const rootInstanceStackCursor : StackCursor <
27
- Container | NoContextT ,
28
- > = createCursor ( NO_CONTEXT ) ;
29
-
30
- function requiredContext < Value > (c: Value | NoContextT): Value {
31
- if ( c === NO_CONTEXT ) {
32
- throw new Error (
33
- 'Expected host context to exist. This error is likely caused by a bug ' +
34
- 'in React. Please file an issue.' ,
35
- ) ;
36
- }
37
22
23
+ function requiredContext < Value > (c: Value | null): Value {
24
+ if ( __DEV__ ) {
25
+ if ( c === null ) {
26
+ console . error (
27
+ 'Expected host context to exist. This error is likely caused by a bug ' +
28
+ 'in React. Please file an issue.' ,
29
+ ) ;
30
+ }
31
+ }
38
32
return ( c : any ) ;
39
33
}
40
34
41
35
function getCurrentRootHostContainer ( ) : null | Container {
42
- const container = rootInstanceStackCursor . current ;
43
- return container === NO_CONTEXT ? null : ( ( container : any ) : Container ) ;
36
+ return rootInstanceStackCursor . current ;
44
37
}
45
38
46
39
function getRootHostContainer ( ) : Container {
@@ -61,7 +54,7 @@ function pushHostContainer(fiber: Fiber, nextRootInstance: Container) {
61
54
// we'd have a different number of entries on the stack depending on
62
55
// whether getRootHostContext() throws somewhere in renderer code or not.
63
56
// So we push an empty value first. This lets us safely unwind on errors.
64
- push ( contextStackCursor , NO_CONTEXT , fiber ) ;
57
+ push ( contextStackCursor , null , fiber ) ;
65
58
const nextRootContext = getRootHostContext ( nextRootInstance ) ;
66
59
// Now that we know this function doesn't throw, replace it.
67
60
pop ( contextStackCursor , fiber ) ;
0 commit comments