Skip to content

Commit d2a176d

Browse files
committed
Remove layout effect warning on the server
1 parent 47cf4e5 commit d2a176d

File tree

2 files changed

+2
-25
lines changed

2 files changed

+2
-25
lines changed

packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,13 +1607,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
16071607
);
16081608
}
16091609

1610-
let finalHTML;
1611-
expect(() => {
1612-
finalHTML = ReactDOMServer.renderToString(<App />);
1613-
}).toErrorDev([
1614-
'useLayoutEffect does nothing on the server',
1615-
'useLayoutEffect does nothing on the server',
1616-
]);
1610+
const finalHTML = ReactDOMServer.renderToString(<App />);
16171611

16181612
assertLog(['App', 'A', 'B']);
16191613

packages/react-server/src/ReactFizzHooks.js

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,23 +440,6 @@ function useRef<T>(initialValue: T): {current: T} {
440440
}
441441
}
442442

443-
export function useLayoutEffect(
444-
create: () => (() => void) | void,
445-
inputs: Array<mixed> | void | null,
446-
) {
447-
if (__DEV__) {
448-
currentHookNameInDev = 'useLayoutEffect';
449-
console.error(
450-
'useLayoutEffect does nothing on the server, because its effect cannot ' +
451-
"be encoded into the server renderer's output format. This will lead " +
452-
'to a mismatch between the initial, non-hydrated UI and the intended ' +
453-
'UI. To avoid this, useLayoutEffect should only be used in ' +
454-
'components that render exclusively on the client. ' +
455-
'See https://reactjs.org/link/uselayouteffect-ssr for common fixes.',
456-
);
457-
}
458-
}
459-
460443
function dispatchAction<A>(
461444
componentIdentity: Object,
462445
queue: UpdateQueue<A>,
@@ -633,7 +616,7 @@ export const HooksDispatcher: Dispatcher = {
633616
useRef,
634617
useState,
635618
useInsertionEffect: noop,
636-
useLayoutEffect,
619+
useLayoutEffect: noop,
637620
useCallback,
638621
// useImperativeHandle is not run in the server environment
639622
useImperativeHandle: noop,

0 commit comments

Comments
 (0)