-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(ui): do not disable eslint-plugin-query for debouncing #103141
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,16 +83,13 @@ function FilterSelector({ | |
| ? !fullTag.predefined && predefinedValues === null | ||
| : true; | ||
|
|
||
| const baseQueryKey = useMemo( | ||
| () => ['global-dashboard-filters-tag-values', tag, selection, searchQuery], | ||
| [tag, selection, searchQuery] | ||
| ); | ||
| const queryKey = useDebouncedValue(baseQueryKey); | ||
|
|
||
| const queryResult = useQuery<string[]>({ | ||
| // Disable exhaustive deps because we want to debounce the query key above | ||
| // eslint-disable-next-line @tanstack/query/exhaustive-deps | ||
| queryKey, | ||
| const queryResult = useQuery({ | ||
| queryKey: useDebouncedValue( | ||
| useMemo( | ||
| () => ['global-dashboard-filters-tag-values', tag, selection, searchQuery], | ||
| [tag, selection, searchQuery] | ||
| ) | ||
| ), | ||
|
Comment on lines
+86
to
+92
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a limitation of the eslint plugin - it doesn’t track the usage through multiple hooks. The easiest way is to just inline the hook calls, which is fine - it doesn’t violate the rules of hooks as they are all still called top-level. we can do this if we don’t need the debounced intermediate value anywhere else.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Wrong Key, Wrong Data Cache MismatchThe
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean yeah, but wasn’t this the case before, too? |
||
| queryFn: async () => { | ||
| const result = await searchBarData.getTagValues(tag, searchQuery); | ||
| return result ?? []; | ||
|
|
||
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.
here, we need the debounced key to calculate
isDebouncing, so we can’t inline it. What we can do though is not rely on closures for the key, but use the providedqueryFunctionContext: React Query gives you the QueryKey into thequeryFnso that you can build self-contained functions.To do this, we need to make sure types flow through correctly so we need:
as conston the actual key, otherwise it’s not a tupleuseQuery<string[]>to justuseQuery. using<>is a type assertion in disguise and destroys type inference for the other 3 type parametersuseQueryhas, so please never do this unless absolutely necessary. Here,getTagValuesalready returns aPromise<string>, so type inference works nicely and with that, we also get type inference back for thequeryFunctionContext. That means we can now accessqueryParamsasctx.queryKey[1].