Skip to content

Commit 21011b1

Browse files
authored
Add apparently redundant optional chaining (#2232)
## Description This didn't crash on the deploy preview of the last merged PR nor locally, so it's kinda hard to localize, but this is my first guess for a quick fix to stop it from crashing.
1 parent f620410 commit 21011b1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/components/sidebar/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import {
2222
useState,
2323
} from "react"
2424
import scrollIntoView from "scroll-into-view-if-needed"
25-
import { useActiveAnchor, useThemeConfig, Collapse } from "nextra-theme-docs"
25+
import {
26+
useActiveAnchor,
27+
useThemeConfig,
28+
Collapse,
29+
ActiveAnchor,
30+
} from "nextra-theme-docs"
2631

2732
import ArrowBarLeft from "@/app/conf/_design-system/pixelarticons/arrow-bar-left.svg?svgr"
2833
import { Anchor } from "@/app/conf/_design-system/anchor"
@@ -249,7 +254,11 @@ function File({
249254

250255
// It is possible that the item doesn't have any route - for example an external link.
251256
const active = item.route && [route, route + "/"].includes(item.route + "/")
252-
const activeAnchor = useActiveAnchor()
257+
/**
258+
* we don't have this bug in staging, but this crashed in prod
259+
* todo: clear this up when we investigate why that happened only in prod
260+
*/
261+
const activeAnchor = useActiveAnchor() as ActiveAnchor | null
253262
const { setMenu } = useMenu()
254263

255264
if (item.type === "separator") {
@@ -277,7 +286,7 @@ function File({
277286
className={cn(
278287
classes.link,
279288
'flex gap-2 before:opacity-25 before:content-["#"]',
280-
activeAnchor[id]?.isActive
289+
activeAnchor?.[id]?.isActive
281290
? classes.active
282291
: classes.inactive,
283292
)}

0 commit comments

Comments
 (0)