Skip to content

Commit ae3f601

Browse files
committed
chore(astro): Add backwards compatibility for ignoring prerendered routes in Astro middleware (#4694)
1 parent 31962a0 commit ae3f601

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

.changeset/tame-lamps-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/astro": patch
3+
---
4+
5+
Add backwards compatibility for ignoring prerendered routes in Astro

packages/astro/src/server/clerk-middleware.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const clerkMiddleware: ClerkMiddleware = (...args: unknown[]): any => {
6262

6363
const astroMiddleware: AstroMiddleware = async (context, next) => {
6464
// if the current page is prerendered, do nothing
65-
if ('isPrerendered' in context && context.isPrerendered) {
65+
if (isPrerenderedPage(context)) {
6666
return next();
6767
}
6868

@@ -129,6 +129,15 @@ export const clerkMiddleware: ClerkMiddleware = (...args: unknown[]): any => {
129129
return astroMiddleware;
130130
};
131131

132+
const isPrerenderedPage = (context: APIContext) => {
133+
return (
134+
// for Astro v5
135+
('isPrerendered' in context && context.isPrerendered) ||
136+
// for Astro v4
137+
('_isPrerendered' in context && context._isPrerendered)
138+
);
139+
};
140+
132141
// TODO-SHARED: Duplicate from '@clerk/nextjs'
133142
const parseHandlerAndOptions = (args: unknown[]) => {
134143
return [

0 commit comments

Comments
 (0)