Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit ccf60b6

Browse files
authored
Update constants and support React.lazy (#1103)
* Update constants to match facebook/react#13444 * Update constants and support Lazy * Fix lint
1 parent d4d3892 commit ccf60b6

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

backend/attachRendererFiber.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ function getInternalReactConstants(version) {
2828
// **********************************************************
2929
if (semver.gte(version, '16.4.3')) {
3030
ReactTypeOfWork = {
31-
IndeterminateComponent: 0,
32-
FunctionalComponent: 1,
33-
FunctionalComponentLazy: 2,
34-
ClassComponent: 3,
35-
ClassComponentLazy: 4,
31+
FunctionalComponent: 0,
32+
FunctionalComponentLazy: 1,
33+
ClassComponent: 2,
34+
ClassComponentLazy: 3,
35+
IndeterminateComponent: 4,
3636
HostRoot: 5,
3737
HostPortal: 6,
3838
HostComponent: 7,
@@ -50,7 +50,9 @@ function getInternalReactConstants(version) {
5050
ReactTypeOfWork = {
5151
IndeterminateComponent: 0,
5252
FunctionalComponent: 1,
53+
FunctionalComponentLazy: -1, // Doesn't exist yet
5354
ClassComponent: 2,
55+
ClassComponentLazy: -1, // Doesn't exist yet
5456
HostRoot: 3,
5557
HostPortal: 4,
5658
HostComponent: 5,
@@ -63,6 +65,7 @@ function getInternalReactConstants(version) {
6365
ContextConsumer: 12,
6466
ContextProvider: 13,
6567
ForwardRef: 14,
68+
ForwardRefLazy: -1, // Doesn't exist yet
6669
Profiler: 15,
6770
Placeholder: 16,
6871
};
@@ -101,13 +104,17 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
101104
var {PerformedWork} = ReactTypeOfSideEffect;
102105
var {
103106
FunctionalComponent,
107+
FunctionalComponentLazy,
104108
ClassComponent,
109+
ClassComponentLazy,
105110
ContextConsumer,
106111
HostRoot,
107112
HostPortal,
108113
HostComponent,
109114
HostText,
110115
Fragment,
116+
ForwardRef,
117+
ForwardRefLazy,
111118
} = ReactTypeOfWork;
112119
var {
113120
ASYNC_MODE_NUMBER,
@@ -116,8 +123,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
116123
CONTEXT_CONSUMER_SYMBOL_STRING,
117124
CONTEXT_PROVIDER_NUMBER,
118125
CONTEXT_PROVIDER_SYMBOL_STRING,
119-
FORWARD_REF_NUMBER,
120-
FORWARD_REF_SYMBOL_STRING,
121126
PROFILER_NUMBER,
122127
PROFILER_SYMBOL_STRING,
123128
STRICT_MODE_NUMBER,
@@ -148,11 +153,20 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
148153
var actualStartTime = null;
149154
var treeBaseDuration = null;
150155

156+
var resolvedType = type;
157+
if (typeof type === 'object' && type !== null) {
158+
if (typeof type.then === 'function') {
159+
resolvedType = type._reactResult;
160+
}
161+
}
162+
151163
switch (fiber.tag) {
152164
case FunctionalComponent:
165+
case FunctionalComponentLazy:
153166
case ClassComponent:
167+
case ClassComponentLazy:
154168
nodeType = 'Composite';
155-
name = getDisplayName(fiber.type);
169+
name = getDisplayName(resolvedType);
156170
publicInstance = fiber.stateNode;
157171
props = fiber.memoizedProps;
158172
state = fiber.memoizedState;
@@ -174,6 +188,13 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
174188
}
175189
children = [];
176190
break;
191+
case ForwardRef:
192+
case ForwardRefLazy:
193+
const functionName = getDisplayName(resolvedType.render, '');
194+
nodeType = 'Special';
195+
name = functionName !== '' ? `ForwardRef(${functionName})` : 'ForwardRef';
196+
children = [];
197+
break;
177198
case HostRoot:
178199
nodeType = 'Wrapper';
179200
children = [];
@@ -221,7 +242,7 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
221242
nodeType = 'Wrapper';
222243
children = [];
223244
break;
224-
default: // Coroutines and yields
245+
default:
225246
const symbolOrNumber = typeof type === 'object' && type !== null
226247
? type.$$typeof
227248
: type;
@@ -259,13 +280,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
259280
name = 'StrictMode';
260281
children = [];
261282
break;
262-
case FORWARD_REF_NUMBER:
263-
case FORWARD_REF_SYMBOL_STRING:
264-
const functionName = getDisplayName(fiber.type.render, '');
265-
nodeType = 'Special';
266-
name = functionName !== '' ? `ForwardRef(${functionName})` : 'ForwardRef';
267-
children = [];
268-
break;
269283
case PLACEHOLDER_NUMBER:
270284
case PLACEHOLDER_SYMBOL_STRING:
271285
nodeType = 'Special';
@@ -357,8 +371,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
357371
}
358372
}
359373

360-
361-
362374
// This is a slightly annoying indirection.
363375
// It is currently necessary because DevTools wants
364376
// to use unique objects as keys for instances.

0 commit comments

Comments
 (0)