Skip to content

Commit 8848b6c

Browse files
committed
Fix dropdown resetting focus
Various dropdown (Table filters, workflow selector, pretty much everything in the ACL tab) would seemingly randomly have their focus reset to the top element every couple of seconds. This would make them hard or even impossible to navigate by users. This patch aims to fix that. The culprit here is a selector hook at the app level. The `Stats` component (the various numbers next to the "Add Event" button) would trigger this hook about every 5 seconds, causing the whole app to rerender and the dropdowns to reset focus. The proposed solution is to not use a selector. This will make our custom hook `useTableFilterStateValidation` effectively only run once on page load. I would argue this is fine, as we do not expect the state to corrupt while the app is running and thus don't need to check for corrupt state everytime the state changes.
1 parent a89897b commit 8848b6c

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect } from "react";
2-
import { useAppDispatch, useAppSelector } from "../store";
2+
import store, { useAppDispatch } from "../store";
33
import { resetCorruptedState } from "../slices/tableFilterSlice";
44

55
/**
@@ -9,10 +9,11 @@ import { resetCorruptedState } from "../slices/tableFilterSlice";
99
*/
1010
export const useTableFilterStateValidation = () => {
1111
const dispatch = useAppDispatch();
12-
const tableFilters = useAppSelector(state => state.tableFilters);
1312

1413
useEffect(() => {
1514
// Check for corrupted state and dispatch reset action if needed
15+
const tableFilters = store.getState().tableFilters;
16+
1617
const hasCorruption =
1718
!Array.isArray(tableFilters.data) ||
1819
!Array.isArray(tableFilters.textFilter) ||
@@ -22,6 +23,5 @@ export const useTableFilterStateValidation = () => {
2223
console.warn("Detected corrupted table filter state, resetting to defaults");
2324
dispatch(resetCorruptedState());
2425
}
25-
// eslint-disable-next-line react-hooks/exhaustive-deps
26-
}, []);
26+
}, [dispatch]);
2727
};

0 commit comments

Comments
 (0)