Skip to content

Commit

Permalink
Small tweaks to SSR to match facebook#14594 (facebook#14618)
Browse files Browse the repository at this point in the history
* Small tweaks to SSR to match facebook#14594

* Remove unnecessary comparison
  • Loading branch information
gaearon authored and jetoneza committed Jan 23, 2019
1 parent 6f0ac82 commit 9a2bf8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions packages/react-dom/src/server/ReactPartialRendererHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,29 +286,26 @@ export function useReducer<S, A>(
}
}

function useMemo<T>(
nextCreate: () => T,
inputs: Array<mixed> | void | null,
): T {
function useMemo<T>(nextCreate: () => T, deps: Array<mixed> | 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;
}

Expand All @@ -330,7 +327,7 @@ function useRef<T>(initialValue: T): {current: T} {

export function useLayoutEffect(
create: () => mixed,
inputs: Array<mixed> | void | null,
deps: Array<mixed> | void | null,
) {
if (__DEV__) {
currentHookNameInDev = 'useLayoutEffect';
Expand Down Expand Up @@ -388,7 +385,7 @@ function dispatchAction<A>(

export function useCallback<T>(
callback: T,
inputs: Array<mixed> | void | null,
deps: Array<mixed> | void | null,
): T {
// Callbacks are passed as they are in the server environment.
return callback;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-test-renderer/src/ReactShallowRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 9a2bf8f

Please sign in to comment.