fix: Hydration mismatch on table collection #604
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
There is a mismatch between the styles applied to table collection between server render and hydration. The client depends on the window width, which causes the mismatch.
Hydration mismatches result in unpredictable behaviour. In this case, the server style is being incorrectly preserved. The table initially renders with the incorrect width, then jumps to the correct position when the screen is resized.
The problem:
Screen.Recording.2025-01-12.at.8.44.48.PM.mov
The proposed fix applies a static style when rendering on the server to prevent the jump, but after mounting, the correct style is then applied. I opted to use
visibility: hidden
for the server state, because otherwise the table immediately performing a transition on page load. It's a brief flash, but less visually impactful than a transition. My approach is opinionated, so I'm open to feedback if you have other suggestions.After the fix is applied:
Screen.Recording.2025-01-12.at.8.46.05.PM.mov
Notion Test Page ID
https://adaminthehills.notion.site/174d424ea49f805cabc7ec5d4a5a2bfe?v=4a4959c0aa884661a01793045a5d421c&pvs=4