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

fix: replace useLayoutEffect into useIsomorphicLayoutEffect for server side rendering #1044

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

khsily
Copy link
Contributor

@khsily khsily commented Jan 16, 2024

This PR will fix the following issue when running on server side.

Warning: 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.

The useIsomorphicLayoutEffect hook fixes this problem by switching between useEffect and useLayoutEffect following the execution environment.

Copy link
Owner

@fkhadra fkhadra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 🙏🏽

@coveralls
Copy link

Coverage Status

coverage: 89.093% (-0.08%) from 89.176%
when pulling cc2a20d on khsily:fix/server-side-effect
into 5759b3f on fkhadra:main.

@fkhadra fkhadra merged commit 3c18d0b into fkhadra:main Jan 16, 2024
2 checks passed
@Grren99
Copy link

Grren99 commented Jan 16, 2024

oh good.. khsily !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants