From 157fcf8fa409d8f61ab72e9be0d4bce73f48db1f Mon Sep 17 00:00:00 2001 From: Michess Date: Mon, 13 Apr 2026 14:01:38 +0200 Subject: [PATCH] fix: RefreshButton handle async onRefresh outside startTransition --- .../home/PublicGames/RefreshButton.tsx | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/client/src/components/home/PublicGames/RefreshButton.tsx b/client/src/components/home/PublicGames/RefreshButton.tsx index 33a1671..88389a1 100644 --- a/client/src/components/home/PublicGames/RefreshButton.tsx +++ b/client/src/components/home/PublicGames/RefreshButton.tsx @@ -2,26 +2,38 @@ import { IconRefresh } from "@tabler/icons-react"; import { useRouter } from "next/navigation"; -import { useTransition } from "react"; +import { useState, useTransition } from "react"; -export default function RefreshButton({ onRefresh }: { onRefresh?: () => void }) { +export default function RefreshButton({ onRefresh }: { onRefresh?: () => Promise | void }) { const router = useRouter(); - const [isLoading, startTransition] = useTransition(); + const [isPending, startTransition] = useTransition(); + const [isLoading, setIsLoading] = useState(false); - function handleRefresh() { - startTransition(() => { - if (onRefresh) onRefresh(); - else router.refresh(); - }); + async function handleRefresh() { + if (onRefresh) { + setIsLoading(true); + try { + await onRefresh(); + } finally { + setIsLoading(false); + } + } else { + startTransition(() => { + router.refresh(); + }); + } } + const loading = isLoading || isPending; + return ( ); }