Skip to content

avoid to get context.session to use export const prerender = true#434

Merged
ascorbic merged 3 commits intoemdash-cms:mainfrom
hayatosc:feat/prerender-true
Apr 11, 2026
Merged

avoid to get context.session to use export const prerender = true#434
ascorbic merged 3 commits intoemdash-cms:mainfrom
hayatosc:feat/prerender-true

Conversation

@hayatosc
Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #399

Type of change

  • Bug fix
  • Feature (requires approved Discussion)
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm --silent lint:json | jq '.diagnostics | length' returns 0
    • lint error but it's not related to this PR
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code

I made this with OpenAI Codex, but I already checked it in my hands.

Copilot AI review requested due to automatic review settings April 10, 2026 16:41
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 10, 2026

🦋 Changeset detected

Latest commit: 8c63d43

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-ai-moderation Patch
@emdash-cms/plugin-atproto Patch
@emdash-cms/plugin-audit-log Patch
@emdash-cms/plugin-color Patch
@emdash-cms/plugin-embeds Patch
@emdash-cms/plugin-forms Patch
@emdash-cms/plugin-webhook-notifier Patch

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@hayatosc
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Apr 10, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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") behind context.isPrerendered checks 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.

Copy link
Copy Markdown
Collaborator

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good addition, thanks.

@ascorbic ascorbic enabled auto-merge (squash) April 11, 2026 13:21
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 11, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@434

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@434

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@434

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@434

emdash

npm i https://pkg.pr.new/emdash@434

create-emdash

npm i https://pkg.pr.new/create-emdash@434

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@434

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@434

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@434

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@434

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@434

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@434

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@434

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@434

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@434

commit: 8c63d43

@ascorbic ascorbic merged commit 9cb5a28 into emdash-cms:main Apr 11, 2026
25 checks passed
@emdashbot emdashbot bot mentioned this pull request Apr 11, 2026
@hayatosc hayatosc deleted the feat/prerender-true branch April 11, 2026 15:23
@emdashbot emdashbot bot mentioned this pull request Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

context.session is accessed on prerendered public routes, breaking export const prerender = true

3 participants