Skip to content

🐛 BUG: dynamic route params as numbers break findPathItemByKey search #3082

@amatiasq

Description

@amatiasq

What version of astro are you using?

1.0.0-beta.7

Are you using an SSR adapter? If so, which one?

no

What package manager are you using?

npm

What operating system are you using?

mac

Describe the Bug

I had export function getStaticPaths() returning [{ year, month, slug }, ...] for a blog and got hit by this error:

 error   [getStaticPath] route pattern matched, but no matching static path found. (/blog/2014/04/asincron-a-y-el-eventloop/)

After some navigating astro's code I found the issue comes from findPathItemByKey() not being able to find a page with such params so I added this line to astro's code:

   if (matchedStaticPath) {
     return matchedStaticPath;
   }

+ debug('test', Array.from(staticPaths.keyed.keys()))
   debug("findPathItemByKey", `Unexpected cache miss looking for ${paramsKey}`);

and a logger in my config file

globalThis._astroGlobalDebug = (...args) => console.log(...args);

And got this printed out:

test [
  '{"month":"04","slug":"asincron-a-y-el-eventloop","year":2014}',
  ...
]
findPathItemByKey Unexpected cache miss looking for {"month":"04","slug":"asincron-a-y-el-eventloop","year":"2014"}

Took me a while to find out the only difference is that year is a number in the cache while it's a string in the key we're looking for it's a string.

IMPORTANT: this is only visible with astro build

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-afsa7x?file=src/pages/[year].astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions