From 63775bf2f59dff691bdeed8c3644e82c8cbee976 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 11 May 2023 23:09:33 +0100 Subject: [PATCH] Revert "fix: hydrate bug on site page" This reverts commit 5edb358a0400e2324a6ac0482ee8f287a50ff50f. --- data/titles.json | 2 +- src/app/site/[site]/[slug]/page.tsx | 35 ++++++++++++++-- src/app/site/[site]/not-found.tsx | 24 +++++++++-- src/components/site/SitePage.tsx | 65 +++-------------------------- 4 files changed, 58 insertions(+), 68 deletions(-) diff --git a/data/titles.json b/data/titles.json index 2636a0fa..fb3de0dc 100644 --- a/data/titles.json +++ b/data/titles.json @@ -5,7 +5,7 @@ "list": [ 10, 30, 12, 32022, 32179, 45, 19, 4583, 4381, 32168, 33446, 33492, 52055, 153, 50143, 51470, 31132, 45089, 50351, 52343, 5825, 51406, 53864, 43086, - 47393, 54315, 50131, 54939, 55096, 55081, 45828, 55343 + 47393, 54315, 50131, 54939, 55096, 55081, 45828 ] } ] diff --git a/src/app/site/[site]/[slug]/page.tsx b/src/app/site/[site]/[slug]/page.tsx index 5d34b72e..c316aded 100644 --- a/src/app/site/[site]/[slug]/page.tsx +++ b/src/app/site/[site]/[slug]/page.tsx @@ -1,7 +1,11 @@ import { Metadata } from "next" +import { notFound } from "next/navigation" + +import { Hydrate, dehydrate } from "@tanstack/react-query" import { SitePage } from "~/components/site/SitePage" import { SITE_URL } from "~/lib/env" +import { useTranslation } from "~/lib/i18n" import getQueryClient from "~/lib/query-client" import { fetchGetPage } from "~/queries/page.server" import { fetchGetSite } from "~/queries/site.server" @@ -68,10 +72,33 @@ export default async function SitePagePage({ slug: string } }) { + const queryClient = getQueryClient() + + const site = await fetchGetSite(params.site, queryClient) + + const page = await fetchGetPage( + { + characterId: site?.characterId, + slug: params.slug, + useStat: true, + }, + queryClient, + ) + + if ( + !page || + new Date(page!.metadata?.content?.date_published || "") > new Date() + ) { + notFound() + } + + const dehydratedState = dehydrate(queryClient) + + const { t } = await useTranslation("site") + return ( - <> - {/* @ts-expect-error Async Server Component */} - - + + + ) } diff --git a/src/app/site/[site]/not-found.tsx b/src/app/site/[site]/not-found.tsx index 0a382510..0d1dad93 100644 --- a/src/app/site/[site]/not-found.tsx +++ b/src/app/site/[site]/not-found.tsx @@ -1,10 +1,26 @@ import { SitePage } from "~/components/site/SitePage" +import { SITE_URL } from "~/lib/env" +import { useTranslation } from "~/lib/i18n" export default async function NotFound() { + const { t } = await useTranslation("site") + return ( - <> - {/* @ts-expect-error Async Server Component */} - - + ) } diff --git a/src/components/site/SitePage.tsx b/src/components/site/SitePage.tsx index 9bbcda62..eb0e528f 100644 --- a/src/components/site/SitePage.tsx +++ b/src/components/site/SitePage.tsx @@ -1,67 +1,18 @@ -import { notFound } from "next/navigation" import serialize from "serialize-javascript" -import { Hydrate, dehydrate } from "@tanstack/react-query" - import { PageContent } from "~/components/common/PageContent" import { PostFooter } from "~/components/site/PostFooter" import PostMeta from "~/components/site/PostMeta" -import { SITE_URL } from "~/lib/env" import { getSiteLink } from "~/lib/helpers" -import { useTranslation } from "~/lib/i18n" -import getQueryClient from "~/lib/query-client" import { ExpandedCharacter, ExpandedNote } from "~/lib/types" -import { fetchGetPage } from "~/queries/page.server" -import { fetchGetSite } from "~/queries/site.server" -export async function SitePage({ - params, +export function SitePage({ + page, + site, }: { - params?: { - site: string - slug: string - } + page?: ExpandedNote + site?: ExpandedCharacter }) { - const { t } = await useTranslation("site") - - const queryClient = getQueryClient() - - let site: ExpandedCharacter | undefined | null - let page: ExpandedNote | undefined | null - if (params) { - site = await fetchGetSite(params.site, queryClient) - page = await fetchGetPage( - { - characterId: site?.characterId, - slug: params.slug, - useStat: true, - }, - queryClient, - ) - } else { - page = { - metadata: { - content: { - title: t("404 - Whoops, this page is gone."), - content: ` -- [Back to Home](/) -- [All posts](/archives) - -![image](${SITE_URL}/assets/404.svg)`, - }, - }, - } as ExpandedNote - } - - if ( - !page || - new Date(page!.metadata?.content?.date_published || "") > new Date() - ) { - notFound() - } - - const dehydratedState = dehydrate(queryClient) - function addPageJsonLd() { return { __html: serialize({ @@ -114,11 +65,7 @@ export async function SitePage({ toc={true} > - {page?.metadata && ( - - - - )} + {page?.metadata && } ) }