diff --git a/src/app/site/[site]/layout.tsx b/src/app/site/[site]/layout.tsx index 59e46ceb..754ca3f3 100644 --- a/src/app/site/[site]/layout.tsx +++ b/src/app/site/[site]/layout.tsx @@ -1,4 +1,5 @@ import { Metadata } from "next" +import { headers } from "next/headers" import { notFound } from "next/navigation" import { Hydrate, dehydrate } from "@tanstack/react-query" @@ -11,7 +12,9 @@ import { SiteHeader } from "~/components/site/SiteHeader" import { FABContainer } from "~/components/ui/FAB" import { SITE_URL } from "~/lib/env" import getQueryClient from "~/lib/query-client" +import { ExpandedNote } from "~/lib/types" import { cn } from "~/lib/utils" +import { fetchGetPage } from "~/queries/page.server" import { fetchGetSite, prefetchGetSiteSubscriptions, @@ -87,7 +90,32 @@ export default async function SiteLayout({ const site = await fetchGetSite(params.site, queryClient) - let page + // https://github.com/vercel/next.js/issues/46618#issuecomment-1450416633 + // Issue: The type will not be updated when the page is redirected. + const pathname = headers().get("x-pathname") + let type: string + switch (pathname) { + case "/": + type = "index" + break + case "/nft": + type = "nft" + break + case "/archive": + type = "archive" + break + case "/search": + type = "search" + break + default: + if (pathname?.startsWith("/tag/")) { + type = "tag" + } else { + type = "post" + } + } + + let page: ExpandedNote | undefined | null if (site?.characterId) { await Promise.all([ prefetchGetSiteSubscriptions( @@ -102,6 +130,21 @@ export default async function SiteLayout({ }, queryClient, ), + new Promise(async (resolve) => { + if (type === "post") { + page = await fetchGetPage( + { + characterId: site.characterId, + slug: pathname?.slice(1), + useStat: true, + }, + queryClient, + ) + resolve() + } else { + resolve() + } + }), ]) } else { notFound() @@ -111,29 +154,13 @@ export default async function SiteLayout({ return ( -
+