From a5fc16df6bcd128721ab5e78fa7635ecc1231ad0 Mon Sep 17 00:00:00 2001 From: Andre Alves Date: Thu, 3 Aug 2023 23:24:21 -0300 Subject: [PATCH 1/2] Fix missing css import on 404 redirect --- packages/astro/src/core/app/index.ts | 2 +- .../src/content/pages/index.md | 7 +++++++ .../ssr-api-route-custom-404/src/pages/404.astro | 4 ++++ .../src/pages/blog/[...ssrPath].astro | 9 +++++++++ .../ssr-api-route-custom-404/src/styles/main.css | 3 +++ packages/astro/test/ssr-404-500-pages.test.js | 11 +++++++++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 packages/astro/test/fixtures/ssr-api-route-custom-404/src/content/pages/index.md create mode 100644 packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/blog/[...ssrPath].astro create mode 100644 packages/astro/test/fixtures/ssr-api-route-custom-404/src/styles/main.css diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 03b73f53a57f..8e1bdb65689e 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -195,7 +195,7 @@ export class App { const newRenderContext = await this.#createRenderContext( url, request, - routeData, + errorRouteData, mod, response.status ); diff --git a/packages/astro/test/fixtures/ssr-api-route-custom-404/src/content/pages/index.md b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/content/pages/index.md new file mode 100644 index 000000000000..c98c9ad9ea37 --- /dev/null +++ b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/content/pages/index.md @@ -0,0 +1,7 @@ +--- +title: Astro +--- + +## Index + +Home page \ No newline at end of file diff --git a/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/404.astro b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/404.astro index 71a4a4d2cb99..c64eee468caf 100644 --- a/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/404.astro +++ b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/404.astro @@ -1 +1,5 @@ +--- +import "../styles/main.css" +--- +

Something went horribly wrong!

diff --git a/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/blog/[...ssrPath].astro b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/blog/[...ssrPath].astro new file mode 100644 index 000000000000..aa40e4d8c9c6 --- /dev/null +++ b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/pages/blog/[...ssrPath].astro @@ -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' +}); +--- diff --git a/packages/astro/test/fixtures/ssr-api-route-custom-404/src/styles/main.css b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/styles/main.css new file mode 100644 index 000000000000..4717ad4b94f6 --- /dev/null +++ b/packages/astro/test/fixtures/ssr-api-route-custom-404/src/styles/main.css @@ -0,0 +1,3 @@ +h1 { + color: red; +} \ No newline at end of file diff --git a/packages/astro/test/ssr-404-500-pages.test.js b/packages/astro/test/ssr-404-500-pages.test.js index 10e311ef983e..ac747a16cc43 100644 --- a/packages/astro/test/ssr-404-500-pages.test.js +++ b/packages/astro/test/ssr-404-500-pages.test.js @@ -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'); From 6a26017adc180e5e903376465de19418af257f51 Mon Sep 17 00:00:00 2001 From: Andre Alves Date: Thu, 3 Aug 2023 23:28:04 -0300 Subject: [PATCH 2/2] Chore: changeset --- .changeset/great-spoons-try.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/great-spoons-try.md diff --git a/.changeset/great-spoons-try.md b/.changeset/great-spoons-try.md new file mode 100644 index 000000000000..e7d0b9009f25 --- /dev/null +++ b/.changeset/great-spoons-try.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix: missing CSS import when 404 server Response redirects to a custom 404 page.