Skip to content

Commit be457ca

Browse files
authored
Small tweaks to SSR to match #14594 (#14618)
* Small tweaks to SSR to match #14594 * Remove unnecessary comparison
1 parent 17d70df commit be457ca

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

Diff for: packages/react-dom/src/server/ReactPartialRendererHooks.js

+13-16
Original file line numberDiff line numberDiff line change
@@ -286,29 +286,26 @@ export function useReducer<S, A>(
286286
}
287287
}
288288

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 {
293290
currentlyRenderingComponent = resolveCurrentlyRenderingComponent();
294291
workInProgressHook = createWorkInProgressHook();
295292

296-
const nextInputs =
297-
inputs !== undefined && inputs !== null ? inputs : [nextCreate];
293+
const nextDeps = deps === undefined ? null : deps;
298294

299-
if (
300-
workInProgressHook !== null &&
301-
workInProgressHook.memoizedState !== null
302-
) {
295+
if (workInProgressHook !== null) {
303296
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+
}
307304
}
308305
}
309306

310307
const nextValue = nextCreate();
311-
workInProgressHook.memoizedState = [nextValue, nextInputs];
308+
workInProgressHook.memoizedState = [nextValue, nextDeps];
312309
return nextValue;
313310
}
314311

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

331328
export function useLayoutEffect(
332329
create: () => mixed,
333-
inputs: Array<mixed> | void | null,
330+
deps: Array<mixed> | void | null,
334331
) {
335332
if (__DEV__) {
336333
currentHookNameInDev = 'useLayoutEffect';
@@ -388,7 +385,7 @@ function dispatchAction<A>(
388385

389386
export function useCallback<T>(
390387
callback: T,
391-
inputs: Array<mixed> | void | null,
388+
deps: Array<mixed> | void | null,
392389
): T {
393390
// Callbacks are passed as they are in the server environment.
394391
return callback;

Diff for: packages/react-test-renderer/src/ReactShallowRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class ReactShallowRenderer {
303303
this._validateCurrentlyRenderingComponent();
304304
this._createWorkInProgressHook();
305305

306-
const nextDeps = deps !== undefined && deps !== null ? deps : null;
306+
const nextDeps = deps !== undefined ? deps : null;
307307

308308
if (
309309
this._workInProgressHook !== null &&

0 commit comments

Comments
 (0)