Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): marketplace page load and caching (#10934)

Ubbe6d6bf308fc7d
diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/MainMarketplacePage/useMainMarketplacePage.ts b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/MainMarketplacePage/useMainMarketplacePage.ts
index 9f3fcc8937..1123ab2eee 100644
--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/components/MainMarketplacePage/useMainMarketplacePage.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/components/MainMarketplacePage/useMainMarketplacePage.ts
@@ -5,8 +5,15 @@ import {
import { StoreAgentsResponse } from "@/app/api/__generated__/models/storeAgentsResponse";
import { CreatorsResponse } from "@/app/api/__generated__/models/creatorsResponse";
+const queryConfig = {
+ staleTime: 60 * 1000, // 60 seconds - match server cache
+ gcTime: 5 * 60 * 1000, // 5 minutes
+ refetchOnWindowFocus: false, // Avoid unnecessary refetches
+ refetchOnMount: false, // Use cached data from server
+};
+
export const useMainMarketplacePage = () => {
- // Below queries are already fetched on server and hydrated properly in cache, hence these requests are fast
+ // Data is prefetched on server and hydrated, these queries will use cached data
const {
data: featuredAgents,
isLoading: isFeaturedAgentsLoading,
@@ -15,6 +22,7 @@ export const useMainMarketplacePage = () => {
{ featured: true },
{
query: {
+ ...queryConfig,
select: (x) => {
return x.data as StoreAgentsResponse;
},
@@ -33,6 +41,7 @@ export const useMainMarketplacePage = () => {
},
{
query: {
+ ...queryConfig,
select: (x) => {
return x.data as StoreAgentsResponse;
},
@@ -48,6 +57,7 @@ export const useMainMarketplacePage = () => {
{ featured: true, sorted_by: "num_agents" },
{
query: {
+ ...queryConfig,
select: (x) => {
return x.data as CreatorsResponse;
},
diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/loading.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/loading.tsx
new file mode 100644
index 0000000000..f69720d4ad
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/loading.tsx
@@ -0,0 +1,5 @@
+import { MainMarketplacePageLoading } from "./components/MainMarketplacePageLoading";
+
+export default function Loading() {
+ return <MainMarketplacePageLoading />;
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/marketplace/page.tsx b/autogpt_platform/frontend/src/app/(platform)/marketplace/page.tsx
index 7186ec54cd..0a2753b0f1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/marketplace/page.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/marketplace/page.tsx
@@ -1,4 +1,5 @@
import { Metadata } from "next";
+import { Suspense } from "react";
import {
prefetchGetV2ListStoreAgentsQuery,
prefetchGetV2ListStoreCreatorsQuery,
@@ -6,8 +7,7 @@ import {
import { getQueryClient } from "@/lib/react-query/queryClient";
import { dehydrate, HydrationBoundary } from "@tanstack/react-query";
import { MainMarkeplacePage } from "./components/MainMarketplacePage/MainMarketplacePage";
-
-export const dynamic = "force-dynamic";
+import { MainMarketplacePageLoading } from "./components/MainMarketplacePageLoading";
// FIX: Correct metadata
export const metadata: Metadata = {
@@ -56,22 +56,45 @@ export const metadata: Metadata = {
export default async function MarketplacePage(): Promise<React.ReactElement> {
const queryClient = getQueryClient();
+ // Prefetch all data on server with proper caching
await Promise.all([
- prefetchGetV2ListStoreAgentsQuery(queryClient, {
- featured: true,
- }),
- prefetchGetV2ListStoreAgentsQuery(queryClient, {
- sorted_by: "runs",
- }),
- prefetchGetV2ListStoreCreatorsQuery(queryClient, {
- featured: true,
- sorted_by: "num_agents",
- }),
+ prefetchGetV2ListStoreAgentsQuery(
+ queryClient,
+ { featured: true },
+ {
+ query: {
+ staleTime: 60 * 1000, // 60 seconds
+ gcTime: 5 * 60 * 1000, // 5 minutes (formerly cacheTime)
+ },
+ },
+ ),
+ prefetchGetV2ListStoreAgentsQuery(
+ queryClient,
+ { sorted_by: "runs", page_size: 1000 },
+ {
+ query: {
+ staleTime: 60 * 1000, // 60 seconds
+ gcTime: 5 * 60 * 1000, // 5 minutes
+ },
+ },
+ ),
+ prefetchGetV2ListStoreCreatorsQuery(
+ queryClient,
+ { featured: true, sorted_by: "num_agents" },
+ {
+ query: {
+ staleTime: 60 * 1000, // 60 seconds
+ gcTime: 5 * 60 * 1000, // 5 minutes
+ },
+ },
+ ),
]);
return (
<HydrationBoundary state={dehydrate(queryClient)}>
- <MainMarkeplacePage />
+ <Suspense fallback={<MainMarketplacePageLoading />}>
+ <MainMarkeplacePage />
+ </Suspense>
</HydrationBoundary>
);
}