-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
fix(theme): make useHistorySelector() hydration-safe + use it read search/hash in theme
#11263
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ [V2]
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Size Change: +457 B (0%) Total Size: 11.5 MB
ℹ️ View Unchanged
|
⚡️ Lighthouse report for the deploy preview of this PR
|
|
Size Change: +454 B (0%) Total Size: 11.9 MB
ℹ️ View Unchanged
|
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Argos
Add this label to run UI visual regression tests. See argos.yml GH action.
pr: bug fix
This PR fixes a bug in a past release.
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.
Motivation
When building in dev mode
docusaurus build --devwe get a lot of React hydration errors as long as we use search/hash URL parameters:On http://localhost:3000/?param or http://localhost:3000/#hash we get:
This is because the theme uses
const {search, hash} = useLocation()to render UI elements, but unfortunately, this hook returns the current/immediate browser search/hash, which is different from what we use on the server (always empty due to our SSG nature).There's probably a way to configure React Router to output hydration-safe values when using
useLocation(), but I'm not 100% sure it's a good idea, it's more risky, and may lead to extra re-renders on things that do not care about search/hash.Instead I made
useHistorySelectorhydration-safe, ensuring that on hydration it always have empty/search like it does on the server.Test Plan
Deploy preview + local
This should fix warnings we get in Argos, and repair it because it was broken due to such new warning introduced due to an iframe embed in v3.8 blog post.
Test links
https://deploy-preview-11263--docusaurus-2.netlify.app/