File tree Expand file tree Collapse file tree 5 files changed +43
-4
lines changed
fixtures/custom-500/src/pages Expand file tree Collapse file tree 5 files changed +43
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " astro " : patch
3+ ---
4+
5+ Fixes a case where styles on the custom 500 error page would not be included
Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ export function collectPagesData(opts: CollectPagesDataOptions): CollectPagesDat
2929 // and is then cached across all future SSR builds. In the past, we've had trouble
3030 // with parallelized builds without guaranteeing that this is called first.
3131 for ( const route of manifest . routes ) {
32- // There's special handling in SSR
32+ // There's special handling in SSR for default components like 404
33+ // However, we need to include 500 pages so they can be properly built with their styles
3334 if ( DEFAULT_COMPONENTS . some ( ( component ) => route . component === component ) ) {
3435 continue ;
3536 }
Original file line number Diff line number Diff line change @@ -91,9 +91,9 @@ function vitePluginSSR(
9191 imports . push ( `const ${ variable } = () => import("${ virtualModuleName } ");` ) ;
9292
9393 const pageData2 = internals . pagesByKeys . get ( pageData . key ) ;
94- if ( pageData2 ) {
95- pageMap . push ( `[ ${ JSON . stringify ( pageData2 . component ) } , ${ variable } ]` ) ;
96- }
94+ // Always add to pageMap even if pageData2 is missing from internals
95+ // This ensures error pages like 500.astro are included in the build
96+ pageMap . push ( `[ ${ JSON . stringify ( pageData2 ?. component || pageData . component ) } , ${ variable } ]` ) ;
9797 i ++ ;
9898 }
9999 }
Original file line number Diff line number Diff line change @@ -137,5 +137,29 @@ describe('Custom 500', () => {
137137 const html = await response . text ( ) ;
138138 assert . equal ( html , '' ) ;
139139 } ) ;
140+
141+ it ( 'renders custom 500 with styles' , async ( ) => {
142+ fixture = await loadFixture ( {
143+ root : './fixtures/custom-500/' ,
144+ output : 'server' ,
145+ adapter : testAdapter ( ) ,
146+ } ) ;
147+ await fixture . build ( ) ;
148+ app = await fixture . loadTestAdapterApp ( ) ;
149+
150+ const request = new Request ( 'http://example.com/' ) ;
151+ const response = await app . render ( request ) ;
152+ assert . equal ( response . status , 500 ) ;
153+
154+ const html = await response . text ( ) ;
155+ const $ = cheerio . load ( html ) ;
156+
157+ // Check that styles from 500.astro are included
158+ // Note: Colors are minified (#ffcccc -> #fcc, #cc0000 -> #c00)
159+ const styles = $ ( 'style' ) . text ( ) ;
160+ assert . match ( styles , / b a c k g r o u n d - c o l o r .* # f c c / ) ;
161+ assert . match ( styles , / c o l o r .* # c 0 0 / ) ;
162+ assert . match ( styles , / f o n t - f a m i l y .* m o n o s p a c e / ) ;
163+ } ) ;
140164 } ) ;
141165} ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,15 @@ const { error } = Astro.props
99<html lang =" en" >
1010<head >
1111 <title >Server error - Custom 500</title >
12+ <style >
13+ body {
14+ background-color: #ffcccc;
15+ color: #cc0000;
16+ }
17+ h1 {
18+ font-family: monospace;
19+ }
20+ </style >
1221</head >
1322<body >
1423 <h1 >Server error</h1 >
You can’t perform that action at this time.
0 commit comments