Skip to content

Commit 20c0811

Browse files
isvictoriousclaude
andcommitted
Fix: Add defensive guards to middleware for prerender safety
Use optional chaining and try-catch to safely handle cases where starlightRoute is not available during prerender. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 5e71b91 commit 20c0811

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/middleware.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { defineMiddleware } from 'astro:middleware';
22

33
export const onRequest = defineMiddleware((context, next) => {
4-
// Set custom logo link to main site instead of docs
5-
if (context.locals.starlightRoute) {
6-
context.locals.starlightRoute.siteTitleHref = 'https://www.tigerdata.com';
4+
try {
5+
// Set custom logo link to main site instead of docs
6+
if (context.locals?.starlightRoute) {
7+
context.locals.starlightRoute.siteTitleHref = 'https://www.tigerdata.com';
8+
}
9+
} catch {
10+
// Safely handle cases where starlightRoute is not available (e.g., 404 prerender)
711
}
812
return next();
913
});

0 commit comments

Comments
 (0)