0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

Handle unmatched 404 when using prerender in dev mode (#5983)

* fix(#5975): unmatched static paths should 404 during dev

* chore: add changeset

Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
Nate Moore 2023-01-25 13:57:32 -06:00 committed by GitHub
parent 03e374f6bc
commit b53e0717b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes a dev server edge case where prerender + getStaticPaths would not 404 on an unmatched route

View file

@ -47,7 +47,7 @@ export async function getParamsAndProps(
routeCache.set(route, routeCacheEntry);
}
const matchedStaticPath = findPathItemByKey(routeCacheEntry.staticPaths, params, route);
if (!matchedStaticPath && !ssr) {
if (!matchedStaticPath && (ssr ? mod.prerender : true)) {
return GetParamsAndPropsError.NoMatchingStaticPath;
}
// Note: considered using Object.create(...) for performance

View file

@ -72,7 +72,9 @@ describe('prerender getStaticPaths - 404 behavior', () => {
it('resolves 404 on pattern match without static path - named params', async () => {
const res = await fixture.fetch('/pizza/provolone-pineapple');
const html = await res.text();
expect(res.status).to.equal(404);
expect(html).to.match(/404/);
});
it('resolves 200 on matching static path - rest params', async () => {
@ -82,7 +84,9 @@ describe('prerender getStaticPaths - 404 behavior', () => {
it('resolves 404 on pattern match without static path - rest params', async () => {
const res = await fixture.fetch('/pizza/pizza-hut');
const html = await res.text();
expect(res.status).to.equal(404);
expect(html).to.match(/404/);
});
});