diff --git a/client/pages/Feed.tsx b/client/pages/Feed.tsx index e2577d60..96dd5096 100644 --- a/client/pages/Feed.tsx +++ b/client/pages/Feed.tsx @@ -112,11 +112,20 @@ export default function Feed() { const fetchFeed = useCallback(async () => { setIsLoading(true); try { - // Parallelize posts and following fetch + // Add timeout to prevent hanging indefinitely + const withTimeout = (promise: Promise, ms: number): Promise => + Promise.race([ + promise, + new Promise((_, reject) => + setTimeout(() => reject(new Error("Request timeout")), ms) + ), + ]); + + // Parallelize posts and following fetch with 10s timeout const [posts, flw] = await Promise.all([ - communityService.getPosts(30), + withTimeout(communityService.getPosts(30), 10000), user?.id - ? aethexSocialService.getFollowing(user.id) + ? withTimeout(aethexSocialService.getFollowing(user.id), 10000) : Promise.resolve([]), ]);