fix(news): resolve null destructuring type errors in article page

.catch(() => null) unioned the query result with null, so destructuring
the first row failed typecheck (TS2488). Return an empty array on failure
instead and drop unused connection/desc imports.
This commit is contained in:
openhands committed 2026-08-05 11:10:16 +02:00
1 parent dc8fb8a6ed
commit 694a24c791
1 file changed
+5 -7
+5 -7
View File
@@ -1,5 +1,4 @@
import { connection } from "next/server"; import { and, asc, eq, inArray } from "drizzle-orm";
import { and, asc, desc, eq, inArray } from "drizzle-orm";
import type { Metadata } from "next"; import type { Metadata } from "next";
import Link from "next/link"; import Link from "next/link";
import { notFound } from "next/navigation"; import { notFound } from "next/navigation";
@@ -26,7 +25,6 @@ import { sanitize } from "@/lib/sanitize";
// See: https://nextjs.org/docs/app/guides/migrating-to-cache-components // See: https://nextjs.org/docs/app/guides/migrating-to-cache-components
export const instant = false; export const instant = false;
type SearchParams = Promise<{ type SearchParams = Promise<{
comment?: string; comment?: string;
reaction?: string; reaction?: string;
@@ -64,7 +62,7 @@ export async function generateMetadata({
.from(WebsiteArticles) .from(WebsiteArticles)
.where(eq(WebsiteArticles.slug, slug)) .where(eq(WebsiteArticles.slug, slug))
.limit(1) .limit(1)
.catch(() => null); .catch(() => []);
if (!article) return { title: "Article" }; if (!article) return { title: "Article" };
return { return {
title: article.title, title: article.title,
@@ -116,7 +114,7 @@ export default async function ArticlePage({
.from(WebsiteArticles) .from(WebsiteArticles)
.where(eq(WebsiteArticles.slug, slug)) .where(eq(WebsiteArticles.slug, slug))
.limit(1) .limit(1)
.catch(() => null); .catch(() => []);
return row ?? null; return row ?? null;
}, },
60, 60,
@@ -231,11 +229,11 @@ export default async function ArticlePage({
> >
{article.image ? ( {article.image ? (
// eslint-disable-next-line @next/next/no-img-element // eslint-disable-next-line @next/next/no-img-element
(<img <img
src={article.image} src={article.image}
alt="" alt=""
style={{ width: "100%", borderRadius: 10, margin: "0 0 1rem" }} style={{ width: "100%", borderRadius: 10, margin: "0 0 1rem" }}
/>) />
) : null} ) : null}
{/* Article body is rich HTML (atom uses TinyMCE) — sanitised server-side. */} {/* Article body is rich HTML (atom uses TinyMCE) — sanitised server-side. */}
<SanitizedHtml <SanitizedHtml