From dcef11d61a481093731c160cea6fadf5ad942ebd Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Mon, 20 Aug 2018 16:56:25 +0100 Subject: [PATCH 1/3] Update constants to match https://github.com/facebook/react/pull/13444 --- backend/attachRendererFiber.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/attachRendererFiber.js b/backend/attachRendererFiber.js index 02b6ce3c86..46be28b048 100644 --- a/backend/attachRendererFiber.js +++ b/backend/attachRendererFiber.js @@ -28,11 +28,11 @@ function getInternalReactConstants(version) { // ********************************************************** if (semver.gte(version, '16.4.3')) { ReactTypeOfWork = { - IndeterminateComponent: 0, - FunctionalComponent: 1, - FunctionalComponentLazy: 2, - ClassComponent: 3, - ClassComponentLazy: 4, + FunctionalComponent: 0, + FunctionalComponentLazy: 1, + ClassComponent: 2, + ClassComponentLazy: 3, + IndeterminateComponent: 4, HostRoot: 5, HostPortal: 6, HostComponent: 7, From da79b0c099b878518fc34aeb9eea0f0583a544aa Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Mon, 20 Aug 2018 17:48:44 +0100 Subject: [PATCH 2/3] Update constants and support Lazy --- backend/attachRendererFiber.js | 36 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/backend/attachRendererFiber.js b/backend/attachRendererFiber.js index 46be28b048..743f69816f 100644 --- a/backend/attachRendererFiber.js +++ b/backend/attachRendererFiber.js @@ -50,7 +50,9 @@ function getInternalReactConstants(version) { ReactTypeOfWork = { IndeterminateComponent: 0, FunctionalComponent: 1, + FunctionalComponentLazy: -1, // Doesn't exist yet ClassComponent: 2, + ClassComponentLazy: -1, // Doesn't exist yet HostRoot: 3, HostPortal: 4, HostComponent: 5, @@ -63,6 +65,7 @@ function getInternalReactConstants(version) { ContextConsumer: 12, ContextProvider: 13, ForwardRef: 14, + ForwardRefLazy: -1, // Doesn't exist yet Profiler: 15, Placeholder: 16, }; @@ -101,13 +104,17 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer): var {PerformedWork} = ReactTypeOfSideEffect; var { FunctionalComponent, + FunctionalComponentLazy, ClassComponent, + ClassComponentLazy, ContextConsumer, HostRoot, HostPortal, HostComponent, HostText, Fragment, + ForwardRef, + ForwardRefLazy, } = ReactTypeOfWork; var { ASYNC_MODE_NUMBER, @@ -148,11 +155,20 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer): var actualStartTime = null; var treeBaseDuration = null; + var resolvedType = type; + if (typeof type === 'object' && type !== null) { + if (typeof type.then === 'function') { + resolvedType = type._reactResult; + } + } + switch (fiber.tag) { case FunctionalComponent: + case FunctionalComponentLazy: case ClassComponent: + case ClassComponentLazy: nodeType = 'Composite'; - name = getDisplayName(fiber.type); + name = getDisplayName(resolvedType); publicInstance = fiber.stateNode; props = fiber.memoizedProps; state = fiber.memoizedState; @@ -174,6 +190,13 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer): } children = []; break; + case ForwardRef: + case ForwardRefLazy: + const functionName = getDisplayName(resolvedType.render, ''); + nodeType = 'Special'; + name = functionName !== '' ? `ForwardRef(${functionName})` : 'ForwardRef'; + children = []; + break; case HostRoot: nodeType = 'Wrapper'; children = []; @@ -221,7 +244,7 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer): nodeType = 'Wrapper'; children = []; break; - default: // Coroutines and yields + default: const symbolOrNumber = typeof type === 'object' && type !== null ? type.$$typeof : type; @@ -259,13 +282,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer): name = 'StrictMode'; children = []; break; - case FORWARD_REF_NUMBER: - case FORWARD_REF_SYMBOL_STRING: - const functionName = getDisplayName(fiber.type.render, ''); - nodeType = 'Special'; - name = functionName !== '' ? `ForwardRef(${functionName})` : 'ForwardRef'; - children = []; - break; case PLACEHOLDER_NUMBER: case PLACEHOLDER_SYMBOL_STRING: nodeType = 'Special'; @@ -357,8 +373,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer): } } - - // This is a slightly annoying indirection. // It is currently necessary because DevTools wants // to use unique objects as keys for instances. From c4242f6be132f82a86a60284816531c57f0eba31 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Mon, 20 Aug 2018 17:53:07 +0100 Subject: [PATCH 3/3] Fix lint --- backend/attachRendererFiber.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/attachRendererFiber.js b/backend/attachRendererFiber.js index 743f69816f..22d8fe5df6 100644 --- a/backend/attachRendererFiber.js +++ b/backend/attachRendererFiber.js @@ -123,8 +123,6 @@ function attachRendererFiber(hook: Hook, rid: string, renderer: ReactRenderer): CONTEXT_CONSUMER_SYMBOL_STRING, CONTEXT_PROVIDER_NUMBER, CONTEXT_PROVIDER_SYMBOL_STRING, - FORWARD_REF_NUMBER, - FORWARD_REF_SYMBOL_STRING, PROFILER_NUMBER, PROFILER_SYMBOL_STRING, STRICT_MODE_NUMBER,