From 46eaef0181cba60a5e0284f58b24925e762c7784 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Tue, 20 Feb 2024 01:19:08 +0100 Subject: [PATCH] docs: fix potential null errors (#2324) --- www/islands/TableOfContents.tsx | 8 ++++++-- www/routes/docs/[...slug].tsx | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/www/islands/TableOfContents.tsx b/www/islands/TableOfContents.tsx index 8cb74b85..f8d390e4 100644 --- a/www/islands/TableOfContents.tsx +++ b/www/islands/TableOfContents.tsx @@ -17,6 +17,8 @@ function setActiveLink( `a[href="#${id}"]`, ) as HTMLElement; + if (tocLink === null) return; + tocLink.classList.add("active"); const rect = tocLink @@ -62,8 +64,10 @@ export function TableOfContents({ headings }: TableOfContentsProps) { const id = headings[i].id; const tocLink = container.querySelector( `a[href="#${id}"]`, - ) as HTMLElement; - tocLink.classList.remove("active"); + ); + if (tocLink !== null) { + tocLink.classList.remove("active"); + } } let activeIdx = visibleList.indexOf(true); diff --git a/www/routes/docs/[...slug].tsx b/www/routes/docs/[...slug].tsx index 143fbdc9..1bfabf89 100644 --- a/www/routes/docs/[...slug].tsx +++ b/www/routes/docs/[...slug].tsx @@ -197,7 +197,7 @@ export default function DocsPage(props: PageProps) {
-
+

{page.title}