Fix measure category filter not applying on initial page load

When navigating back to the measures page with a ?category query parameter, the filter wasn't applied to the initial Relay query. The component state was initialized from the URL, but the Relay fragment loaded with its default category: null. Add a mount effect that triggers a refetch with the initial category parameter.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-20 11:20:40 +01:00
parent 6e9cee9d34
commit fce754cff4

View File

@@ -193,6 +193,22 @@ export default function MeasuresPage({ queryRef }: MeasuresPageProps) {
});
};
const initialUrlCategory = useRef(urlCategory);
useEffect(() => {
if (initialUrlCategory.current) {
startTransition(() => {
refetch(
{
query: null,
state: null,
category: initialUrlCategory.current,
},
{ fetchPolicy: "network-only" },
);
});
}
}, [refetch, startTransition]);
useEffect(() => {
if (urlCategory !== categoryFilter) {
setCategoryFilter(urlCategory);