Skip to content

fix(searchbutton): fix react hydration error#1384

Merged
shortcuts merged 4 commits into
algolia:nextfrom
nissy-dev:fix-ssr-error-for-react18
Jun 24, 2022
Merged

fix(searchbutton): fix react hydration error#1384
shortcuts merged 4 commits into
algolia:nextfrom
nissy-dev:fix-ssr-error-for-react18

Conversation

@nissy-dev

Copy link
Copy Markdown
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

netlify Bot commented May 3, 2022

Copy link
Copy Markdown

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

codesandbox-ci Bot commented May 3, 2022

Copy link
Copy Markdown

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
Copy Markdown
Contributor Author

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

@shortcuts shortcuts left a comment

Copy link
Copy Markdown
Member

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

Comment thread packages/docsearch-react/src/DocSearchButton.tsx Outdated

@shortcuts shortcuts left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@nissy-dev

nissy-dev commented Jun 26, 2022

Copy link
Copy Markdown
Contributor Author

@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