Fix slug override with / value#3293
Conversation
This is mostly an edit to include a co-author I forgot to add in the previous commit. Co-authored-by: Armand Philippot <git@armand.philippot.eu>
🦋 Changeset detectedLatest commit: 68feac2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for astro-starlight ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
ArmandPhilippot
left a comment
There was a problem hiding this comment.
I also tested in my repro by updating the code in node_modules and it works, nice finding! 🙌🏽
|
Feel free to disregard but I’d like to suggest a slightly more readable version of the export function slugToParam(slug: string): string | undefined {
if (slug === 'index' || slug === '' || slug === '/') return undefined;
if (slug.endsWith('/index')) return slug.slice(0, -6);
return slug;
} |
delucis
left a comment
There was a problem hiding this comment.
Thanks for the great work investigating and fixing this @ArmandPhilippot & @HiDeoo! LGTM.
@kevinzunigacuellar Definitely feel free to open a refactor PR — always happy to see those 💖
* main: (26 commits) [ci] release (withastro#3296) Fix slug override with `/` value (withastro#3293) i18n(fr): update `guides/i18n.mdx` (withastro#3294) i18n(ko-KR): update `i18n.mdx` (withastro#3292) [ci] release (withastro#3286) Revert withastro#3281 (withastro#3291) i18n(de): update `guides/i18n.mdx` (withastro#3289) Fix Astro i18n config default locale issue (withastro#3288) docs: fix `t.exists()` documentation + example (withastro#3287) Make targeting sidebar links with CSS a little easier (withastro#3281) i18n(fr): update `resources/plugins.mdx` (withastro#3284) Extract main padding to CSS custom property (withastro#3282) i18n(de): update plugins translation (withastro#3285) i18n(ko-KR): update `plugins.mdx` (withastro#3283) Add link to the codeblock-fullscreen plugin (withastro#3279) Fix TabItem typo in zh-cn authoring-content.mdx (withastro#3268) (withastro#3269) [ci] format i18n(ru): update translations (withastro#3270) Update `sharp` in docs & examples to latest (withastro#3261) Add missing danish UI translations (withastro#3252) ...
Co-authored-by: Armand Philippot <git@armand.philippot.eu>

Description
This PR fixes an issue preventing to override the slug of a page with the
slugfrontmatter property using the/value.Huge thanks to @ArmandPhilippot for all the help in debugging this issue and setting up many reproductions pinpointing the problem.
As visible in this StackBlitz example, a dynamic route parameter set to the
/value ends beingundefinedinAstro.params. In Starlight, we have aslugToParamfunction which does not handle this case.With Starlight
0.32and the introduction of route data, we are now always callinggetRoute()(which usesgetRouteBySlugParam) with thecontext.params.slugvalue (whereas before this was only used in SSR). When explicitly setting theslugfrontmatter property to/, this results in thegetRouteBySlugParam()being called with anundefinedparameter but as theslugToParam()function does not handle this case, it's failing to find the route (which instead of having a key ofundefinedhas a key of/).Another local test to verify the fix:
Run
pnpm devin thedocs/directory.Delete the
docs/src/content/docs/index.mdxfile.Add the following frontmatter field to
docs/src/content/docs/reference/configuration.mdx:Before the fix, opening
http://localhost:4321/would result in a404error. After the fix, it correctly displays the configuration reference page.