Description
When using EmDash with Astro, setting export const prerender = true on a public page causes runtime errors because EmDash middleware accesses context.session even on prerendered routes.
Problem
EmDash middleware reads context.session on public routes without checking whether the route is prerendered.
|
const sessionUser = await context.session?.get("user"); |
|
const isAuthenticated = !!(await context.session?.get("user")); |
Fix
On public route, avoid any context.session access when context.isPrerendered is true.
for example:
const sessionUser = context.isPrerendered
? null
: await context.session?.get("user");
Steps to reproduce
- Create an EmDash site with
output: "server" and the EmDash integration enabled.
- In a public page such as
src/pages/index.astro, add:
export const prerender = true
- Start dev server
- Go
http://localhost:4321
Environment
emdash: 0.1.0
astro: 6.1.3
@astrojs/cloudflare: 13.1.7
Description
When using EmDash with Astro, setting
export const prerender = trueon a public page causes runtime errors because EmDash middleware accessescontext.sessioneven on prerendered routes.Problem
EmDash middleware reads context.session on public routes without checking whether the route is prerendered.
emdash/packages/core/src/astro/middleware.ts
Line 201 in 7aa3de2
emdash/packages/core/src/astro/middleware.ts
Line 353 in 7aa3de2
Fix
On public route, avoid any context.session access when
context.isPrerenderedis true.for example:
Steps to reproduce
output: "server"and the EmDash integration enabled.src/pages/index.astro, add:http://localhost:4321Environment
emdash:0.1.0astro:6.1.3@astrojs/cloudflare:13.1.7