-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Bugfix: Refresh search results when clearing category filter #142853
Bugfix: Refresh search results when clearing category filter #142853
Conversation
Pinging @elastic/fleet (Team:Fleet) |
@@ -16,13 +16,11 @@ export const fieldsToSearch = ['name', 'title']; | |||
export function useLocalSearch(packageList: IntegrationCardItem[]) { | |||
const localSearchRef = useRef<LocalSearch>(new LocalSearch(searchIdField)); | |||
|
|||
useEffect(() => { |
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.
I am not sure why this useEffect was needed? is it best practice to only change ref.current in a useEffect? I can't find anything which says so. I've tested the search behavour and everything still works.
The bug was a race condition, the results are rendered before the useEffect is called, meaning the ref contains the stale search resaults. Removing the useEffect means the results are instantly updated removing the race.
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.
Good catch!
I searched about the use of ref
in useEffect
and actually it seems that they don't work like one would expect, causing this type of race conditions. There are some examples in this article: https://medium.com/@teh_builder/ref-objects-inside-useeffect-hooks-eb7c15198780
Thanks, TIL :)
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.
LGTM
💚 Build Succeeded
Metrics [docs]Async chunks
To update your PR or re-run it, just comment with: cc @hop-dev |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
#142960) (cherry picked from commit 022e59f) Co-authored-by: Mark Hopkin <[email protected]>
Summary
When clearing a category filter, results were not being refreshed. Here, after clearing the communications category, the aws results should be shown again:
broken.mov
Removing the useEffect fixes this:
fixed.mov