From 209ab3e4b02fe61821b05cb4e0e3d03e559d3070 Mon Sep 17 00:00:00 2001 From: tylerslaton Date: Mon, 21 Oct 2024 12:20:31 -0400 Subject: [PATCH] fix: preload agents and thread on agents screen This fixes an issue described in #202 where the agents that were listed would not always have the correct thread counts on the page. To fix this, we now preload the agents and threaads. Signed-off-by: tylerslaton --- ui/admin/app/routes/_auth.agents._index.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ui/admin/app/routes/_auth.agents._index.tsx b/ui/admin/app/routes/_auth.agents._index.tsx index 372aebd2..18edf61d 100644 --- a/ui/admin/app/routes/_auth.agents._index.tsx +++ b/ui/admin/app/routes/_auth.agents._index.tsx @@ -4,7 +4,7 @@ import { ColumnDef, createColumnHelper } from "@tanstack/react-table"; import { SquarePen, Trash } from "lucide-react"; import { useMemo } from "react"; import { $path } from "remix-routes"; -import useSWR from "swr"; +import useSWR, { preload } from "swr"; import { Agent } from "~/lib/model/agents"; import { AgentService } from "~/lib/service/api/agentService"; @@ -23,6 +23,14 @@ import { } from "~/components/ui/tooltip"; import { useAsync } from "~/hooks/useAsync"; +export async function clientLoader() { + await Promise.all([ + preload(AgentService.getAgents.key(), AgentService.getAgents), + preload(ThreadsService.getThreads.key(), ThreadsService.getThreads), + ]); + return null; +} + export default function Threads() { const navigate = useNavigate(); const getThreads = useSWR(ThreadsService.getThreads.key(), () =>