Replies: 1 comment
-
@abaf6789 Can you please explain (or show a template repo) of how you implemented SSR in a RN web app. Thank you. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/exports/Image/index.js
In a Server-Side Rendering (SSR) scenario, we aim for the page to render tags directly on the initial load to avoid discrepancies in content that would cause re-renders during the client-side hydration process, thereby enhancing user experience. However, the use of the React useState hook for initializing state in the code snippet above may lead to issues.
The root of the problem lies in the logic of the useState initialization function, which attempts to determine if the image has been loaded. If the image is not loaded, it sets the state to IDLE. On the server side, since there is no concept of image loading, the state is always set to IDLE, resulting in tags not being included in the server-rendered HTML. When the client takes over rendering (i.e., during the hydration process), React detects a mismatch between the server-rendered content and the expected state on the client, triggering a re-render. This not only affects performance but may also cause the user to see a flicker in the page content.
Below is the modified code:
Beta Was this translation helpful? Give feedback.
All reactions