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

Add support for React.memo #1204

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions backend/attachRendererFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ function getInternalReactConstants(version) {
CONTEXT_PROVIDER_SYMBOL_STRING: 'Symbol(react.provider)',
FORWARD_REF_NUMBER: 0xead0,
FORWARD_REF_SYMBOL_STRING: 'Symbol(react.forward_ref)',
MEMO_NUMBER: 0xead3,
MEMO_SYMBOL_STRING: 'Symbol(react.memo)',
PROFILER_NUMBER: 0xead2,
PROFILER_SYMBOL_STRING: 'Symbol(react.profiler)',
PURE_NUMBER: 0xead3,
PURE_SYMBOL_STRING: 'Symbol(react.pure)',
STRICT_MODE_NUMBER: 0xeacc,
STRICT_MODE_SYMBOL_STRING: 'Symbol(react.strict_mode)',
SUSPENSE_NUMBER: 0xead1,
Expand Down Expand Up @@ -143,6 +143,8 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
HostText,
Fragment,
ForwardRef,
MemoComponent,
SimpleMemoComponent,
} = ReactTypeOfWork;
var {
CONCURRENT_MODE_NUMBER,
Expand All @@ -154,8 +156,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
CONTEXT_PROVIDER_SYMBOL_STRING,
PROFILER_NUMBER,
PROFILER_SYMBOL_STRING,
PURE_NUMBER,
PURE_SYMBOL_STRING,
STRICT_MODE_NUMBER,
STRICT_MODE_SYMBOL_STRING,
SUSPENSE_NUMBER,
Expand All @@ -166,6 +166,7 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
// TODO: we might want to change the data structure
// once we no longer suppport Stack versions of `getData`.
function getDataFiber(fiber: Object): DataType {
var elementType = fiber.elementType;
var type = fiber.type;
var key = fiber.key;
var ref = fiber.ref;
Expand Down Expand Up @@ -279,6 +280,17 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
nodeType = 'Wrapper';
children = [];
break;
case MemoComponent:
case SimpleMemoComponent:
nodeType = 'Special';
if (elementType.displayName) {
name = elementType.displayName;
} else {
const displayName = type.displayName || type.name;
name = displayName ? `Memo(${displayName})` : 'Memo';
}
children = [];
break;
default:
const symbolOrNumber = typeof type === 'object' && type !== null
? type.$$typeof
Expand All @@ -289,17 +301,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer):
: symbolOrNumber;

switch (switchValue) {
case PURE_NUMBER:
case PURE_SYMBOL_STRING:
nodeType = 'Special';
if (type.displayName) {
name = type.displayName;
} else {
const displayName = type.render.displayName || type.render.name;
name = displayName ? `Pure(${displayName})` : 'Pure';
}
children = [];
break;
case CONCURRENT_MODE_NUMBER:
case CONCURRENT_MODE_SYMBOL_STRING:
case DEPRECATED_ASYNC_MODE_SYMBOL_STRING:
Expand Down