From be457ca685b113c08e43f30df226eedbdef5d8a2 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 18 Jan 2019 00:52:13 +0000 Subject: [PATCH] Small tweaks to SSR to match #14594 (#14618) * Small tweaks to SSR to match #14594 * Remove unnecessary comparison --- .../src/server/ReactPartialRendererHooks.js | 29 +++++++++---------- .../src/ReactShallowRenderer.js | 2 +- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/packages/react-dom/src/server/ReactPartialRendererHooks.js b/packages/react-dom/src/server/ReactPartialRendererHooks.js index 558c34064b2c5..e8ceb7bb5b22c 100644 --- a/packages/react-dom/src/server/ReactPartialRendererHooks.js +++ b/packages/react-dom/src/server/ReactPartialRendererHooks.js @@ -286,29 +286,26 @@ export function useReducer( } } -function useMemo( - nextCreate: () => T, - inputs: Array | void | null, -): T { +function useMemo(nextCreate: () => T, deps: Array | void | null): T { currentlyRenderingComponent = resolveCurrentlyRenderingComponent(); workInProgressHook = createWorkInProgressHook(); - const nextInputs = - inputs !== undefined && inputs !== null ? inputs : [nextCreate]; + const nextDeps = deps === undefined ? null : deps; - if ( - workInProgressHook !== null && - workInProgressHook.memoizedState !== null - ) { + if (workInProgressHook !== null) { const prevState = workInProgressHook.memoizedState; - const prevInputs = prevState[1]; - if (areHookInputsEqual(nextInputs, prevInputs)) { - return prevState[0]; + if (prevState !== null) { + if (nextDeps !== null) { + const prevDeps = prevState[1]; + if (areHookInputsEqual(nextDeps, prevDeps)) { + return prevState[0]; + } + } } } const nextValue = nextCreate(); - workInProgressHook.memoizedState = [nextValue, nextInputs]; + workInProgressHook.memoizedState = [nextValue, nextDeps]; return nextValue; } @@ -330,7 +327,7 @@ function useRef(initialValue: T): {current: T} { export function useLayoutEffect( create: () => mixed, - inputs: Array | void | null, + deps: Array | void | null, ) { if (__DEV__) { currentHookNameInDev = 'useLayoutEffect'; @@ -388,7 +385,7 @@ function dispatchAction( export function useCallback( callback: T, - inputs: Array | void | null, + deps: Array | void | null, ): T { // Callbacks are passed as they are in the server environment. return callback; diff --git a/packages/react-test-renderer/src/ReactShallowRenderer.js b/packages/react-test-renderer/src/ReactShallowRenderer.js index 890596721b8d2..a8ec56f014aee 100644 --- a/packages/react-test-renderer/src/ReactShallowRenderer.js +++ b/packages/react-test-renderer/src/ReactShallowRenderer.js @@ -303,7 +303,7 @@ class ReactShallowRenderer { this._validateCurrentlyRenderingComponent(); this._createWorkInProgressHook(); - const nextDeps = deps !== undefined && deps !== null ? deps : null; + const nextDeps = deps !== undefined ? deps : null; if ( this._workInProgressHook !== null &&