Skip to content

Commit

Permalink
Remove layout effect warning on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Mar 15, 2023
1 parent 47cf4e5 commit d2a176d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1607,13 +1607,7 @@ describe('ReactDOMServerSelectiveHydration', () => {
);
}

let finalHTML;
expect(() => {
finalHTML = ReactDOMServer.renderToString(<App />);
}).toErrorDev([
'useLayoutEffect does nothing on the server',
'useLayoutEffect does nothing on the server',
]);
const finalHTML = ReactDOMServer.renderToString(<App />);

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

Expand Down
19 changes: 1 addition & 18 deletions packages/react-server/src/ReactFizzHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,23 +440,6 @@ function useRef<T>(initialValue: T): {current: T} {
}
}

export function useLayoutEffect(
create: () => (() => void) | void,
inputs: Array<mixed> | void | null,
) {
if (__DEV__) {
currentHookNameInDev = 'useLayoutEffect';
console.error(
'useLayoutEffect does nothing on the server, because its effect cannot ' +
"be encoded into the server renderer's output format. This will lead " +
'to a mismatch between the initial, non-hydrated UI and the intended ' +
'UI. To avoid this, useLayoutEffect should only be used in ' +
'components that render exclusively on the client. ' +
'See https://reactjs.org/link/uselayouteffect-ssr for common fixes.',
);
}
}

function dispatchAction<A>(
componentIdentity: Object,
queue: UpdateQueue<A>,
Expand Down Expand Up @@ -633,7 +616,7 @@ export const HooksDispatcher: Dispatcher = {
useRef,
useState,
useInsertionEffect: noop,
useLayoutEffect,
useLayoutEffect: noop,
useCallback,
// useImperativeHandle is not run in the server environment
useImperativeHandle: noop,
Expand Down

0 comments on commit d2a176d

Please sign in to comment.