[ML] Anomaly Explorer: Prevent crash on anomaly table filter (#213075)

Fix for: https://github.com/elastic/kibana/issues/212569
From what I found, the issue was with the `useUrlStateService` after
changes introduced in https://github.com/elastic/kibana/pull/203224,
which made the service more generic.

When filtering causes the `explorer` to remount the `AnomaliesTable`,
pagination state updates are triggered before the effect that sets
`setCallback.current` executes.

Initializing the ref with `setState` ensures its availability from the
first render.


https://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6
This commit is contained in:
Robert Jaszczurek 2025-03-07 00:18:49 +01:00 committed by GitHub
parent 3fdb04d294
commit 0210468548
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -291,7 +291,7 @@ export const useUrlStateService = <K extends Accessor, T>(
? state?.[optionsRef.current.pageKey]
: state;
const setCallback = useRef<typeof setState>();
const setCallback = useRef<typeof setState>(setState);
useEffect(() => {
setCallback.current = setState;