withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
44.25k stars 2.3k forks source link

Top level dynamic routes are prioritized #11394

Open mrchantey opened 2 weeks ago

mrchantey commented 2 weeks ago

What version of starlight are you using?

0.24.5

What version of astro are you using?

4.10.2

What package manager are you using?

npm

What operating system are you using?

Windows

What browser are you using?

Chrome

Describe the Bug

According to route priority order static files are prioritized over dynamic routes, however top level dynamic routes break starlight routes.

To see the effect click on the primary action button which redirects to a dynamic route.

An example use for this is github-style top level username routes: [username]/[project].astro

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-61gc9w?file=src%2Fpages%2F%5Busername%5D%2F%5Bproject%5D.astro

Participation

delucis commented 2 weeks ago

Thanks for the issue @mrchantey.

In the docs, what is meant by “static routes” are routes without any parameters (e.g. src/pages/something.astro), but Starlight pages are actually generated using a [...path].astro route under the hood, so I think the two-part, user-defined dynamic route in your example is winning.

One thing I’m seeing with your reproduction is that if I build the project (I added the Node adapter to do this), the production site does serve Starlight’s pages before hitting the dynamic route. See https://stackblitz.com/edit/github-61gc9w-qyzhpu and then run npm run preview. So there’s an inconsistency between the dev server and the build in this case.

I’m not 100% sure what the expected behaviour is here based on the docs, but hopefully it’s that the static pages always win and this is just a dev server bug.

mrchantey commented 2 weeks ago

Oh awesome thats super helpful, yeah i hadn't tried a preview but noticed the static files in dist and thought somehow they were being skipped 😅 Ill have a play with it, might be able to do a dev-mode-only redirect or something.

delucis commented 2 weeks ago

I chatted a bit with @Fryuni who implemented the routing priority rules in Astro and he said that unfortunately the dev server behaviour is the correct behaviour as currently specced. So technically it working in production with the Node adapter is a “bug” 😅

Seems a bit of a limitation to me, so we’ll chat to see if there’s a way to make this more easily configurable. To my mind users would always want a Starlight slug for which there is a content file to be served, and then their dynamic SSR routes to kick in.

delucis commented 2 weeks ago

OK, moving this across to the main Astro repo for @Fryuni to think about how to handle best 🫡