-
Notifications
You must be signed in to change notification settings - Fork 584
Replace dependency react-window #3070
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: main
Are you sure you want to change the base?
Replace dependency react-window #3070
Conversation
Signed-off-by: Parship Chowdhury <i.am.parship@gmail.com>
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
useEffect(() => { | ||
if (hasMountedRef.current && inputRef.current) { | ||
inputRef.current.focus(); | ||
} | ||
} | ||
const checked = Boolean(checkedCount) && checkedCount === filtered.length; | ||
const title = `Click to ${checked ? 'unselect' : 'select'} all ${ | ||
filtered.length < options.length ? 'filtered ' : '' | ||
}options`; | ||
hasMountedRef.current = true; | ||
}); |
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.
The useEffect
hook is missing a dependency array, which means it will run after every render. This creates a potential focus management issue where the input could be focused unexpectedly during re-renders triggered by state changes or other effects.
Consider adding an appropriate dependency array to control when this effect runs:
useEffect(() => {
if (hasMountedRef.current && inputRef.current) {
inputRef.current.focus();
}
hasMountedRef.current = true;
}, []); // Empty dependency array to run only on mount
Alternatively, if the intent is to focus only when specific conditions change, include those conditions in the dependency array to make the behavior more predictable and avoid unexpected focus shifts during user interaction.
useEffect(() => { | |
if (hasMountedRef.current && inputRef.current) { | |
inputRef.current.focus(); | |
} | |
} | |
const checked = Boolean(checkedCount) && checkedCount === filtered.length; | |
const title = `Click to ${checked ? 'unselect' : 'select'} all ${ | |
filtered.length < options.length ? 'filtered ' : '' | |
}options`; | |
hasMountedRef.current = true; | |
}); | |
useEffect(() => { | |
if (hasMountedRef.current && inputRef.current) { | |
inputRef.current.focus(); | |
} | |
hasMountedRef.current = true; | |
}, []); |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3070 +/- ##
==========================================
+ Coverage 98.13% 98.16% +0.03%
==========================================
Files 257 257
Lines 8004 8085 +81
Branches 2092 2118 +26
==========================================
+ Hits 7855 7937 +82
+ Misses 149 148 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Parship Chowdhury <i.am.parship@gmail.com>
const onListScrolled = useMemo( | ||
() => | ||
_debounce(() => { | ||
setFocusedIndex(null); | ||
}, 80), | ||
[] | ||
); |
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.
The useMemo
with an empty dependency array creates a new debounced function on mount, but this approach doesn't properly clean up the debounced function when the component unmounts. This can lead to memory leaks as the debounced function may continue to hold references to component state.
Consider using useCallback
with a cleanup function in useEffect
:
const onListScrolled = useCallback(
_debounce(() => {
setFocusedIndex(null);
}, 80),
[]
);
useEffect(() => {
return () => {
// Clean up the debounced function on unmount
onListScrolled.cancel();
};
}, [onListScrolled]);
This ensures the debounced function is properly cleaned up when the component unmounts, preventing potential memory leaks and race conditions.
const onListScrolled = useMemo( | |
() => | |
_debounce(() => { | |
setFocusedIndex(null); | |
}, 80), | |
[] | |
); | |
const onListScrolled = useCallback( | |
_debounce(() => { | |
setFocusedIndex(null); | |
}, 80), | |
[] | |
); | |
useEffect(() => { | |
return () => { | |
// Clean up the debounced function on unmount | |
onListScrolled.cancel(); | |
}; | |
}, [onListScrolled]); |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
Signed-off-by: Parship Chowdhury <i.am.parship@gmail.com>
bvaughn/react-window#302 |
https://github.com/tanstack looks like a reasonable choice |
Which problem is this PR solving?
Description of the changes
How was this change tested?
Checklist
jaeger
:make lint test
jaeger-ui
:npm run lint
andnpm run test