Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing CSS when 404 server Response redirects to a custom 404 page #7946

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/great-spoons-try.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix: missing CSS import when 404 server Response redirects to a custom 404 page.
2 changes: 1 addition & 1 deletion packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class App {
const newRenderContext = await this.#createRenderContext(
url,
request,
routeData,
errorRouteData,
mod,
response.status
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Astro
---

## Index

Home page
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
---
import "../styles/main.css"
---

<h1>Something went horribly wrong!</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
import { getEntry } from 'astro:content';
const { ssrPath } = Astro.params;
const page = await getEntry('pages', ssrPath === undefined ? 'index' : ssrPath);
if (!page) return new Response(null, {
status: 404,
statusText: 'Not found'
});
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 {
color: red;
}
11 changes: 11 additions & 0 deletions packages/astro/test/ssr-404-500-pages.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ describe('404 and 500 pages', () => {
expect($('h1').text()).to.equal('Something went horribly wrong!');
});

it('404 page returned when a route does not match and imports are included', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/blog/fake/route');
const routeData = app.match(request);
const response = await app.render(request, routeData);
expect(response.status).to.equal(404);
const html = await response.text();
const $ = cheerio.load(html);
expect($('head link')).to.have.a.lengthOf(1);
});

it('404 page returned when there is an 404 response returned from route', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/causes-404');
Expand Down