Skip to content

Commit 6bcd757

Browse files
committed
rework resolveFiberType
1 parent 5429c6e commit 6bcd757

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import {
4949
patch as patchConsole,
5050
registerRenderer as registerRendererWithConsole,
5151
} from './console';
52-
import {isMemo, isForwardRef} from 'react-is';
5352

5453
import type {Fiber} from 'react-reconciler/src/ReactFiber';
5554
import type {
@@ -325,6 +324,10 @@ export function getInternalReactConstants(
325324
PROFILER_SYMBOL_STRING,
326325
SCOPE_NUMBER,
327326
SCOPE_SYMBOL_STRING,
327+
FORWARD_REF_NUMBER,
328+
FORWARD_REF_SYMBOL_STRING,
329+
MEMO_NUMBER,
330+
MEMO_SYMBOL_STRING,
328331
} = ReactSymbols;
329332

330333
function resolveFiberType(type: any) {
@@ -333,14 +336,18 @@ export function getInternalReactConstants(
333336
if (typeof type.then === 'function') {
334337
return type._reactResult;
335338
}
336-
if (isForwardRef(type)) {
337-
return type.render;
338-
}
339-
// recursively resolving memo type in case of memo(forwardRef(Component))
340-
if (isMemo(type)) {
341-
return resolveFiberType(type.type);
339+
const typeSymbol = getTypeSymbol(type);
340+
switch (typeSymbol) {
341+
case MEMO_NUMBER:
342+
case MEMO_SYMBOL_STRING:
343+
// recursively resolving memo type in case of memo(forwardRef(Component))
344+
return resolveFiberType(type.type);
345+
case FORWARD_REF_NUMBER:
346+
case FORWARD_REF_SYMBOL_STRING:
347+
return type.render;
348+
default:
349+
return type;
342350
}
343-
return type;
344351
}
345352

346353
// NOTICE Keep in sync with shouldFilterFiber() and other get*ForFiber methods

packages/react-is/src/__tests__/ReactIs-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ describe('ReactIs', () => {
110110
const RefForwardingComponent = React.forwardRef((props, ref) => null);
111111
expect(ReactIs.isValidElementType(RefForwardingComponent)).toBe(true);
112112
expect(ReactIs.typeOf(<RefForwardingComponent />)).toBe(ReactIs.ForwardRef);
113-
expect(ReactIs.isForwardRef(RefForwardingComponent)).toBe(true);
114113
expect(ReactIs.isForwardRef(<RefForwardingComponent />)).toBe(true);
115114
expect(ReactIs.isForwardRef({type: ReactIs.StrictMode})).toBe(false);
116115
expect(ReactIs.isForwardRef(<div />)).toBe(false);

0 commit comments

Comments
 (0)