Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small tweaks to SSR to match #14594 #14618

Merged
merged 2 commits into from Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 13 additions & 16 deletions packages/react-dom/src/server/ReactPartialRendererHooks.js
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
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