-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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(v2): keep DocSearch state on remounts #3297
fix(v2): keep DocSearch state on remounts #3297
Conversation
Deploy preview for docusaurus-2 ready! Built with commit 9f503cd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey
What just wondering, why using refs instead of useMemo/useCallback? Do you need stronger guarantee or something?
searchClient.addAlgoliaAgent('docusaurus', siteMetadata.docusaurusVersion); | ||
|
||
return searchClient; | ||
}).current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oooh this is a funny pattern I've never seen before :)
@slorber (I was able to use |
Ahah I see it's this annoying problem again :) (see facebook/react#16956) |
1 similar comment
Ahah I see it's this annoying problem again :) (see facebook/react#16956) |
one suggestion culd be to handle the memoization directly in the lib, and wrap your component in a parent component whose role is to make the props "stable" That's a bit annoying but at least it could prevent end users to have to do this themselves, so the lib is more idiomatic to use |
Motivation
The Docusaurus navbar remounts at a certain screen resize. This creates new variable references for objects and functions passed to the
DocSearchModal
component, resulting in a rerender of DocSearch that then loses the previous state (because we listen to these reference changes in our component).This PR keeps references of DocSearch options by using
useMemo
anduseRef
.Have you read the Contributing Guidelines on pull requests?
Yes.
Test Plan
Before
After