avoid to get context.session to use export const prerender = true#434
avoid to get context.session to use export const prerender = true#434ascorbic merged 3 commits intoemdash-cms:mainfrom
context.session to use export const prerender = true#434Conversation
🦋 Changeset detectedLatest commit: 8c63d43 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Pull request overview
This PR fixes Astro prerender compatibility by ensuring EmDash’s Astro middleware does not touch context.session during prerendered requests (enabling export const prerender = true on public pages without runtime errors).
Changes:
- Guard
context.session?.get("user")behindcontext.isPrerenderedchecks in middleware (both the early public-route fast path and the D1 sessions/authenticated branch). - Add a unit test that asserts prerendered public pages do not access
context.session. - Add a changeset to publish the fix as a patch.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/astro/middleware.ts | Skips session reads when context.isPrerendered is true to avoid prerender runtime errors. |
| packages/core/tests/unit/astro/middleware-prerender.test.ts | New regression test that throws if context.session is accessed during prerender. |
| .changeset/light-donuts-reply.md | Declares a patch release for the fix (but currently formatted incorrectly). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
905317e to
4ef8ff2
Compare
ascorbic
left a comment
There was a problem hiding this comment.
Good addition, thanks.
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
What does this PR do?
Closes #399
Type of change
Checklist
pnpm typecheckpassespnpm --silent lint:json | jq '.diagnostics | length'returns 0pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure
I made this with OpenAI Codex, but I already checked it in my hands.