THE ABOVE ERROR OCCURS when I tried to load more than two data with suspense (streaming). I'm using Next JS 13.4 with App router by the way.
export const serverApi = async <T>(
url: string,
init?: RequestInit
): Promise<T> => {
const response = await fetch(BASE_URL.API + url, init);
if (!response.ok) {
throw new Error(response.statusText);
}
return await (response.json() as Promise<T>);
};
export const getArticles = async () => {
return await serverApi<Article[]>(API.ARTICLES, {
cache: "no-store",
});
};
export const getArticle = async (id: string) => {
return await serverApi<Article>(API.ARTICLE_WITH_ID(id), {
cache: "no-store",
});
};
const Header = async () => {
return (
<header className="relative w-full flex items-center justify-center">
<div />
<HeaderNavigation />
<Suspense fallback={<HeaderProfileSpinner />}>
{/* @ts-ignore */}
<HeaderProfile />
</Suspense>
</header>
);
};
const HeaderProfile = async () => {
const cookie = getCookie();
const queryClient = getQueryClient();
await queryClient.prefetchQuery(USER_QUERY_KEYS.me(), () =>
getUserMe(cookie)
);
const dehydratedState = dehydrate(queryClient);
return (
<Hydrate state={dehydratedState}>
<HeaderProfileImage />
</Hydrate>
);
};
I use API like this. I'm using Page Router for API. For more details, I use Prisma for ORM, Postgres (Supabase) for DB, and use Vercel deployment. I think 'connection closed' means that the server aborts the connection when one of the streaming has resolved, and it wasn't like I expected. I thought the whole point of streaming is rendering multiple contents in parallel but it didn't work. It's kinda weird that the error doesn't happen in localhost.