Skip to content

Commit

Permalink
rework resolveFiberType
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmd committed Nov 5, 2019
1 parent 5429c6e commit 6bcd757
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
23 changes: 15 additions & 8 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
patch as patchConsole,
registerRenderer as registerRendererWithConsole,
} from './console';
import {isMemo, isForwardRef} from 'react-is';

import type {Fiber} from 'react-reconciler/src/ReactFiber';
import type {
Expand Down Expand Up @@ -325,6 +324,10 @@ export function getInternalReactConstants(
PROFILER_SYMBOL_STRING,
SCOPE_NUMBER,
SCOPE_SYMBOL_STRING,
FORWARD_REF_NUMBER,
FORWARD_REF_SYMBOL_STRING,
MEMO_NUMBER,
MEMO_SYMBOL_STRING,
} = ReactSymbols;

function resolveFiberType(type: any) {
Expand All @@ -333,14 +336,18 @@ export function getInternalReactConstants(
if (typeof type.then === 'function') {
return type._reactResult;
}
if (isForwardRef(type)) {
return type.render;
}
// recursively resolving memo type in case of memo(forwardRef(Component))
if (isMemo(type)) {
return resolveFiberType(type.type);
const typeSymbol = getTypeSymbol(type);
switch (typeSymbol) {
case MEMO_NUMBER:
case MEMO_SYMBOL_STRING:
// recursively resolving memo type in case of memo(forwardRef(Component))
return resolveFiberType(type.type);
case FORWARD_REF_NUMBER:
case FORWARD_REF_SYMBOL_STRING:
return type.render;
default:
return type;
}
return type;
}

// NOTICE Keep in sync with shouldFilterFiber() and other get*ForFiber methods
Expand Down
1 change: 0 additions & 1 deletion packages/react-is/src/__tests__/ReactIs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ describe('ReactIs', () => {
const RefForwardingComponent = React.forwardRef((props, ref) => null);
expect(ReactIs.isValidElementType(RefForwardingComponent)).toBe(true);
expect(ReactIs.typeOf(<RefForwardingComponent />)).toBe(ReactIs.ForwardRef);
expect(ReactIs.isForwardRef(RefForwardingComponent)).toBe(true);
expect(ReactIs.isForwardRef(<RefForwardingComponent />)).toBe(true);
expect(ReactIs.isForwardRef({type: ReactIs.StrictMode})).toBe(false);
expect(ReactIs.isForwardRef(<div />)).toBe(false);
Expand Down

0 comments on commit 6bcd757

Please sign in to comment.