@samitouri / QOS-React / commits / be457ca685

Small tweaks to SSR to match #14594 (#14618)

* Small tweaks to SSR to match #14594 * Remove unnecessary comparison

Dan Abramov committed Jan 18, 2019 at 00:52 UTC be457ca685b113c08e43f30df226eedbdef5d8a2
2 files changed +14 -17
packages/react-dom/src/server/ReactPartialRendererHooks.js
+13 -16
@@ -286,29 +286,26 @@ export function useReducer<S, A>(
286 }
287 }
288
289 -function useMemo<T>(
290 - nextCreate: () => T,
291 - inputs: Array<mixed> | void | null,
292 -): T {
289 +function useMemo<T>(nextCreate: () => T, deps: Array<mixed> | void | null): T {
290 currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
291 workInProgressHook = createWorkInProgressHook();
292
296 - const nextInputs =
297 - inputs !== undefined && inputs !== null ? inputs : [nextCreate];
293 + const nextDeps = deps === undefined ? null : deps;
294
299 - if (
300 - workInProgressHook !== null &&
301 - workInProgressHook.memoizedState !== null
302 - ) {
295 + if (workInProgressHook !== null) {
296 const prevState = workInProgressHook.memoizedState;
304 - const prevInputs = prevState[1];
305 - if (areHookInputsEqual(nextInputs, prevInputs)) {
306 - return prevState[0];
297 + if (prevState !== null) {
298 + if (nextDeps !== null) {
299 + const prevDeps = prevState[1];
300 + if (areHookInputsEqual(nextDeps, prevDeps)) {
301 + return prevState[0];
302 + }
303 + }
304 }
305 }
306
307 const nextValue = nextCreate();
311 - workInProgressHook.memoizedState = [nextValue, nextInputs];
308 + workInProgressHook.memoizedState = [nextValue, nextDeps];
309 return nextValue;
310 }
311
@@ -330,7 +327,7 @@ function useRef<T>(initialValue: T): {current: T} {
327
328 export function useLayoutEffect(
329 create: () => mixed,
333 - inputs: Array<mixed> | void | null,
330 + deps: Array<mixed> | void | null,
331 ) {
332 if (__DEV__) {
333 currentHookNameInDev = 'useLayoutEffect';
@@ -388,7 +385,7 @@ function dispatchAction<A>(
385
386 export function useCallback<T>(
387 callback: T,
391 - inputs: Array<mixed> | void | null,
388 + deps: Array<mixed> | void | null,
389 ): T {
390 // Callbacks are passed as they are in the server environment.
391 return callback;
packages/react-test-renderer/src/ReactShallowRenderer.js
+1 -1
@@ -303,7 +303,7 @@ class ReactShallowRenderer {
303 this._validateCurrentlyRenderingComponent();
304 this._createWorkInProgressHook();
305
306 - const nextDeps = deps !== undefined && deps !== null ? deps : null;
306 + const nextDeps = deps !== undefined ? deps : null;
307
308 if (
309 this._workInProgressHook !== null &&