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: hydration error on small device (chat-header) #546

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mrcodiator
Copy link

@mrcodiator mrcodiator commented Nov 16, 2024

Issue & Resolution Note for Vercel AI Chat Repo
Issue:#535

The chat app encountered a hydration mismatch error due to the use of the useWindowSize hook. This occurred because server-side rendered content couldn’t access the window dimensions, causing a mismatch when the client-side rendered content based on the actual window width.

Resolution:

To fix this, we added a client-side mounting check using an isMounted state tracker:

Initially rendered a simplified header that matched the SSR output.
After the client was mounted, we rendered the full header with width-dependent content.
This ensures consistent rendering between server and client, following React’s SSR best practices.

Fixed Component: components/chat-header.tsx
error-vercel-chat

Copy link

vercel bot commented Nov 16, 2024

@mrcodiator is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@mrcodiator mrcodiator changed the title fix: hydration error on small device (chat-header) fix: hydration error on small device (chat-header) #535 Nov 16, 2024
@mrcodiator mrcodiator changed the title fix: hydration error on small device (chat-header) #535 fix: hydration error on small device (chat-header) Nov 16, 2024
@mrcodiator mrcodiator mentioned this pull request Nov 16, 2024
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.

1 participant