From 5070e9e75a548c1d19ec82bd48601b6d968bb126 Mon Sep 17 00:00:00 2001 From: xdkaine <55013938+xdkaine@users.noreply.github.com> Date: Fri, 5 Jun 2026 15:20:43 -0700 Subject: [PATCH] Revert "fix to refetch and stop the cache of invalid/old responses" This reverts commit 7ffea5bdee5b8147a871a0358809aec8dfdeb719. --- my-app/app/admin/dashboard/page.tsx | 3 --- my-app/app/creator/dashboard/page.tsx | 8 -------- my-app/app/page.tsx | 1 - my-app/app/pods/deployed/page.tsx | 3 --- my-app/app/pods/templates/page.tsx | 5 +---- my-app/contexts/auth-context.tsx | 3 --- my-app/hooks/use-api-state.ts | 7 +------ my-app/lib/api.ts | 14 +------------- 8 files changed, 3 insertions(+), 41 deletions(-) diff --git a/my-app/app/admin/dashboard/page.tsx b/my-app/app/admin/dashboard/page.tsx index 6507245..384822e 100644 --- a/my-app/app/admin/dashboard/page.tsx +++ b/my-app/app/admin/dashboard/page.tsx @@ -12,14 +12,11 @@ import { NodeResources } from "@/app/admin/dashboard/node-resources" import { DashboardQuickActions } from "@/components/dashboard/dashboard-quick-actions" import { Button } from "@/components/ui/button" import { RefreshCw } from "lucide-react" -import { useAuth } from "@/contexts/auth-context" export default function AdminDashboardPage() { - const { authState } = useAuth() // Fetch unified dashboard data const { data: dashboardData, loading, error, refetch } = useApiState({ fetchFn: getDashboardData, - enabled: authState.authenticated === true && authState.isAdmin === true, deps: [] }) diff --git a/my-app/app/creator/dashboard/page.tsx b/my-app/app/creator/dashboard/page.tsx index b0c80da..4b195af 100644 --- a/my-app/app/creator/dashboard/page.tsx +++ b/my-app/app/creator/dashboard/page.tsx @@ -10,21 +10,14 @@ import { ErrorDisplay } from "@/components/ui/error-display"; import { Copy, CopyPlusIcon, Edit } from "lucide-react"; import Link from "next/link"; import { Button } from "@/components/ui/button"; -import { useAuth } from "@/contexts/auth-context"; export default function CreatorDashboardPage() { - const { authState } = useAuth(); - const creatorOrAdmin = - authState.authenticated === true && - (authState.isCreator === true || authState.isAdmin === true); - const { data: templates, loading: templatesLoading, error: templatesError, } = useApiState({ fetchFn: getAllPodTemplates, - enabled: creatorOrAdmin, }); const { @@ -33,7 +26,6 @@ export default function CreatorDashboardPage() { error: unpublishedError, } = useApiState({ fetchFn: getUnpublishedTemplates, - enabled: creatorOrAdmin, }); const publishedCount = templates?.length || 0; diff --git a/my-app/app/page.tsx b/my-app/app/page.tsx index d32f3b2..dae5e97 100644 --- a/my-app/app/page.tsx +++ b/my-app/app/page.tsx @@ -42,7 +42,6 @@ export default function Page() { error: dashboardError, } = useApiState({ fetchFn: getUserDashboard, - enabled: authState.authenticated === true, }); // Extract data from the unified response diff --git a/my-app/app/pods/deployed/page.tsx b/my-app/app/pods/deployed/page.tsx index d3173af..687354a 100644 --- a/my-app/app/pods/deployed/page.tsx +++ b/my-app/app/pods/deployed/page.tsx @@ -10,7 +10,6 @@ import { useApiState } from "@/hooks/use-api-state" import { deletePod, getDeployedPods } from "@/lib/api" import { DeployedPod } from "@/lib/types" import { SectionCards } from "@/app/pods/deployed/deployed-pods-cards" -import { useAuth } from "@/contexts/auth-context" import { AlertDialog, AlertDialogAction, @@ -24,10 +23,8 @@ import { export default function Page() { const [alertOpen, setAlertOpen] = useState(false) const [selectedPod, setSelectedPod] = useState(null) - const { authState } = useAuth() const { data: pods, loading, error } = useApiState({ fetchFn: getDeployedPods, - enabled: authState.authenticated === true, }) const handleDeleteClick = (pod: DeployedPod) => { diff --git a/my-app/app/pods/templates/page.tsx b/my-app/app/pods/templates/page.tsx index 9fcd066..7206a47 100644 --- a/my-app/app/pods/templates/page.tsx +++ b/my-app/app/pods/templates/page.tsx @@ -9,15 +9,12 @@ import { SectionCards } from "@/app/pods/templates/pod-templates-cards" import { getPodTemplates } from "@/lib/api" import { PodDeployDialog } from "@/components/pod-deploy-dialog" import { usePodDeployment } from "@/hooks/use-pod-deployment" -import { useAuth } from "@/contexts/auth-context" export default function Page() { const { isDialogOpen, selectedPod, openDeployDialog, closeDeployDialog } = usePodDeployment() - const { authState } = useAuth() - + const { data: pods, loading, error } = useApiState({ fetchFn: getPodTemplates, - enabled: authState.authenticated === true, }) const pageHeader = ( diff --git a/my-app/contexts/auth-context.tsx b/my-app/contexts/auth-context.tsx index ccfb587..92c6f0a 100644 --- a/my-app/contexts/auth-context.tsx +++ b/my-app/contexts/auth-context.tsx @@ -8,7 +8,6 @@ import { useEffect, useCallback, } from "react"; -import { clearRequestCache } from "@/lib/api"; interface SessionData { authenticated: boolean; @@ -111,7 +110,6 @@ export function AuthProvider({ children }: { children: ReactNode }) { // Clear cache to force fresh request sessionCache = null; sessionPromise = null; - clearRequestCache(); setAuthState((prev) => ({ ...prev, loading: true })); await checkSession(); }, [checkSession]); @@ -122,7 +120,6 @@ export function AuthProvider({ children }: { children: ReactNode }) { // Clear cache and update state sessionCache = null; sessionPromise = null; - clearRequestCache(); setAuthState({ authenticated: false, loading: false, diff --git a/my-app/hooks/use-api-state.ts b/my-app/hooks/use-api-state.ts index dad6c0c..d4a9491 100644 --- a/my-app/hooks/use-api-state.ts +++ b/my-app/hooks/use-api-state.ts @@ -3,7 +3,6 @@ import { useEffect, useState } from "react" interface UseApiStateOptions { fetchFn: () => Promise deps?: React.DependencyList - enabled?: boolean } interface UseApiStateReturn { @@ -13,7 +12,7 @@ interface UseApiStateReturn { refetch: () => void } -export function useApiState({ fetchFn, deps = [], enabled = true }: UseApiStateOptions): UseApiStateReturn { +export function useApiState({ fetchFn, deps = [] }: UseApiStateOptions): UseApiStateReturn { const [data, setData] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) @@ -32,10 +31,6 @@ export function useApiState({ fetchFn, deps = [], enabled = true }: UseApiSta } useEffect(() => { - if (!enabled) { - setLoading(true) - return - } fetchData() }, deps) diff --git a/my-app/lib/api.ts b/my-app/lib/api.ts index 5a840f0..79a8381 100644 --- a/my-app/lib/api.ts +++ b/my-app/lib/api.ts @@ -23,11 +23,6 @@ const requestCache = new Map< >(); const CACHE_DURATION = 5000; // 5 seconds for deduplication -// Clear all cached/in-flight requests -export function clearRequestCache(): void { - requestCache.clear(); -} - // Helper function to handle request deduplication async function deduplicatedFetch( key: string, @@ -54,15 +49,8 @@ async function deduplicatedFetch( // Cache the promise requestCache.set(key, { promise, timestamp: now }); - promise.catch(() => { - const entry = requestCache.get(key); - if (entry && entry.timestamp === now) { - requestCache.delete(key); - } - }); - // Clean up cache after completion - promise.then(() => { + promise.finally(() => { setTimeout(() => { const entry = requestCache.get(key); if (entry && entry.timestamp === now) {