Skip to content

fix(astro): include styles in custom 500 error pages#14488

Merged
florian-lefebvre merged 8 commits intowithastro:mainfrom
olcanebrem:fix-500-styles
Oct 8, 2025
Merged

fix(astro): include styles in custom 500 error pages#14488
florian-lefebvre merged 8 commits intowithastro:mainfrom
olcanebrem:fix-500-styles

Conversation

@olcanebrem
Copy link
Copy Markdown
Contributor

Fixes issue where custom 500.astro pages did not include their styles when rendered dynamically in SSR mode.

Root Cause

Error pages like 500.astro were not always added to the SSR pageMap when pageData2 was missing from internals.pagesByKeys.
This prevented Vite from importing the page during build, so CSS was never collected into the manifest.

Changes

  • Modified plugin-ssr.ts to always add pages to pageMap, even if pageData2 is undefined
  • Added fallback to use pageData.component in those cases
  • Extended custom-500 fixture to include inline styles
  • Added regression test: verifies that styles from 500.astro are included in SSR output (checks minified CSS)

Impact

  • Ensures custom 500 error pages behave consistently with other routes
  • Fix is build-time only; no runtime overhead
  • Custom 500.astro remains optional — if missing, Astro still falls back to default error overlay

Closes #13272

Changes

  • 500 error pages now properly include their styles in SSR
  • Added regression test to prevent future regressions

Testing

  • Added new integration test under test/custom-500.test.js
  • Verified fixture builds and renders styles correctly
  • All existing tests continue to pass (pnpm test)

Docs

  • No user-facing docs changes required
  • Behavior matches existing 404 error page behavior

Fixes issue where custom `500.astro` pages did not include their styles when rendered dynamically in SSR mode.

### Root Cause
Error pages like `500.astro` were not always added to the SSR `pageMap` when `pageData2` was missing from `internals.pagesByKeys`.
This prevented Vite from importing the page during build, so CSS was never collected into the manifest.

### Changes
- Modified `plugin-ssr.ts` to always add pages to `pageMap`, even if `pageData2` is undefined
- Added fallback to use `pageData.component` in those cases
- Extended `custom-500` fixture to include inline styles
- Added regression test: verifies that styles from `500.astro` are included in SSR output (checks minified CSS)

### Impact
- Ensures custom 500 error pages behave consistently with other routes
- Fix is build-time only; no runtime overhead
- Custom `500.astro` remains optional — if missing, Astro still falls back to default error overlay

Closes withastro#13272
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Oct 4, 2025

🦋 Changeset detected

Latest commit: 853ef25

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

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 github-actions bot added pkg: astro Related to the core `astro` package (scope) semver: major Change triggers a `major` release labels Oct 4, 2025
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a major changeset. A reviewer will merge this at the next release if approved.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Oct 4, 2025

CodSpeed Performance Report

Merging #14488 will not alter performance

Comparing olcanebrem:fix-500-styles (853ef25) with main (d1b3409)1

Summary

✅ 6 untouched

Footnotes

  1. No successful run was found on main (ae73aa4) during the generation of this report, so d1b3409 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@olcanebrem
Copy link
Copy Markdown
Contributor Author

The CI failure looks unrelated to this change (flaky test in dev/restart.test.js).
Could a maintainer please re-run the workflow? 🙏

@florian-lefebvre
Copy link
Copy Markdown
Member

Hi! Can you undo all the changesets deletions?

@florian-lefebvre florian-lefebvre removed the semver: major Change triggers a `major` release label Oct 6, 2025
@olcanebrem
Copy link
Copy Markdown
Contributor Author

Hi! Can you undo all the changesets deletions?

restored

Copy link
Copy Markdown
Member

@florian-lefebvre florian-lefebvre left a comment

Choose a reason for hiding this comment

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

Thank you!

@florian-lefebvre florian-lefebvre merged commit badc929 into withastro:main Oct 8, 2025
6 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom 500 page does not include styles

2 participants