summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2023-01-25 13:57:32 -0600
committerGravatar GitHub <noreply@github.com> 2023-01-25 13:57:32 -0600
commitb53e0717b7f6b042baaeec7f87999e99c76c031c (patch)
tree65105bdb9858f9c3f0fe18c177b494c784c312ad
parent03e374f6bcbe7dc51f0cbcf4cfd15f00bac799be (diff)
downloadastro-b53e0717b7f6b042baaeec7f87999e99c76c031c.tar.gz
astro-b53e0717b7f6b042baaeec7f87999e99c76c031c.tar.zst
astro-b53e0717b7f6b042baaeec7f87999e99c76c031c.zip
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>
-rw-r--r--.changeset/fluffy-cherries-shake.md5
-rw-r--r--packages/astro/src/core/render/core.ts2
-rw-r--r--packages/astro/test/ssr-prerender-get-static-paths.test.js4
3 files changed, 10 insertions, 1 deletions
diff --git a/.changeset/fluffy-cherries-shake.md b/.changeset/fluffy-cherries-shake.md
new file mode 100644
index 000000000..818ce7a42
--- /dev/null
+++ b/.changeset/fluffy-cherries-shake.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes a dev server edge case where prerender + getStaticPaths would not 404 on an unmatched route
diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts
index 6c486ae34..862ada7c8 100644
--- a/packages/astro/src/core/render/core.ts
+++ b/packages/astro/src/core/render/core.ts
@@ -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
diff --git a/packages/astro/test/ssr-prerender-get-static-paths.test.js b/packages/astro/test/ssr-prerender-get-static-paths.test.js
index 4ffa8677e..b0253eabf 100644
--- a/packages/astro/test/ssr-prerender-get-static-paths.test.js
+++ b/packages/astro/test/ssr-prerender-get-static-paths.test.js
@@ -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/);
});
});