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(searchbutton): fix react hydration error #1384

Merged
merged 4 commits into from Jun 24, 2022

Conversation

nissy-dev
Copy link
Contributor

fix #1242

After upgrading React v18, the error of react hydration mismatch happens not only in dev but also in prod.
I fixed this error by using useEffect, following the Next.js documentation, https://nextjs.org/docs/messages/react-hydration-error.

@netlify
Copy link

netlify bot commented May 3, 2022

Deploy Preview for docsearch ready!

Name Link
🔨 Latest commit 375144e
🔍 Latest deploy log https://app.netlify.com/sites/docsearch/deploys/62b5b0196e1b3b0008764847
😎 Deploy Preview https://deploy-preview-1384--docsearch.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 3, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 375144e:

Sandbox Source
Vanilla Configuration

@nissy-dev
Copy link
Contributor Author

@shortcuts If you have time, I'd be happy to have you review it

Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

IIRC we switched to useMemo to prevent a UI flash, but it was not the solution and did not reverted the change. cc @francoischalifour

Can you confirm this fixes the production only? Locally I was still getting the error for dev builds

packages/docsearch-react/src/DocSearchButton.tsx Outdated Show resolved Hide resolved
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

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

Thanks!

@nissy-dev
Copy link
Contributor Author

nissy-dev commented Jun 26, 2022

@shortcuts

Can you confirm this fixes the production only? Locally I was still getting the error for dev builds

I confirmed both production build and dev build and they work well. I got the error at the first too, but realized it was due to the build cache. After removing the .next directory and running next dev again, the error disappeared and the behavior was as expected.

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.

Server-rendering hydration warning in Next.js
2 participants