From 2d89492d73142ed5c7cea9448d841a9892e66598 Mon Sep 17 00:00:00 2001 From: Matt Kane Date: Mon, 6 Jan 2025 11:49:39 +0000 Subject: [PATCH] fix: don't match all paths when returning empty array from getStaticPaths (#12906) --- .changeset/gorgeous-cameras-smile.md | 5 +++++ .../astro/src/core/render/params-and-props.ts | 1 - .../src/pages/empty-paths/[...slug].astro | 18 ++++++++++++++++++ packages/astro/test/routing-priority.test.js | 5 +++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 .changeset/gorgeous-cameras-smile.md create mode 100644 packages/astro/test/fixtures/routing-priority/src/pages/empty-paths/[...slug].astro diff --git a/.changeset/gorgeous-cameras-smile.md b/.changeset/gorgeous-cameras-smile.md new file mode 100644 index 0000000000..c158b8e11c --- /dev/null +++ b/.changeset/gorgeous-cameras-smile.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes a bug that caused pages that return an empty array from getStaticPath to match every path diff --git a/packages/astro/src/core/render/params-and-props.ts b/packages/astro/src/core/render/params-and-props.ts index f8799115b0..7b3f60b251 100644 --- a/packages/astro/src/core/render/params-and-props.ts +++ b/packages/astro/src/core/render/params-and-props.ts @@ -47,7 +47,6 @@ export async function getProps(opts: GetParamsAndPropsOptions): Promise { base, }); - if (!staticPaths.length) return {}; // The pathname used here comes from the server, which already encoded. // Since we decided to not mess up with encoding anymore, we need to decode them back so the parameters can match // the ones expected from the users diff --git a/packages/astro/test/fixtures/routing-priority/src/pages/empty-paths/[...slug].astro b/packages/astro/test/fixtures/routing-priority/src/pages/empty-paths/[...slug].astro new file mode 100644 index 0000000000..67130d51e8 --- /dev/null +++ b/packages/astro/test/fixtures/routing-priority/src/pages/empty-paths/[...slug].astro @@ -0,0 +1,18 @@ +--- +export function getStaticPaths() { + return [] +} +const { slug } = Astro.params +--- + + + + + + {slug} + + +

empty-paths/[...slug].astro

+

slug: {slug}

+ + diff --git a/packages/astro/test/routing-priority.test.js b/packages/astro/test/routing-priority.test.js index d4203595d8..888c28d104 100644 --- a/packages/astro/test/routing-priority.test.js +++ b/packages/astro/test/routing-priority.test.js @@ -107,6 +107,11 @@ const routes = [ url: '/empty-slug/undefined', fourOhFour: true, }, + { + description: 'do not match /empty-paths/hello to empty-paths/[...slug].astro', + url: '/empty-paths/hello', + fourOhFour: true, + }, { description: 'matches /api/catch/a.json to api/catch/[...slug].json.ts', url: '/api/catch/a.json',