bito-code-review[bot] commented on code in PR #44837:
URL: https://github.com/apache/superset/pull/44837#discussion_r4150071277
##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/hooks/useItemStateManager.ts:
##########
@@ -75,13 +75,27 @@ export function useItemStateManager(
const [orderedIds, setOrderedIds] = useState<string[]>(initialOrder);
const [renderedIds, setRenderedIds] =
useState<string[]>(DEFAULT_EMPTY_ARRAY);
+ const removedItemsRef = useRef(removedItems);
+ useEffect(() => {
+ removedItemsRef.current = removedItems;
+ }, [removedItems]);
+
+ const clearPendingRemovalTimers = useCallback(() => {
+ Object.values(removedItemsRef.current).forEach(removal => {
+ if (removal?.isPending && removal.timerId) {
+ clearTimeout(removal.timerId);
+ }
+ });
+ }, []);
+
const resetState = useCallback(() => {
+ clearPendingRemovalTimers();
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Stale ref misses pending timer</b></div>
<div id="fix">
`removedItemsRef` is synced in a passive `useEffect`, so
`clearPendingRemovalTimers` (called from `resetState` and unmount cleanup)
reads the previous `removedItems` when a pending removal is set in the same
tick — the newest `timerId` is missed and fires after reset, repopulating
`removedItems`. Assign the ref during render (latest-ref pattern) so
`clearPendingRemovalTimers` always sees current pending timers.
</div>
</div>
<small><i>Code Review Run #77762b</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]