Skip to content

Refactor autogenerated sidebar groups#3618

Merged
delucis merged 24 commits into
withastro:mainfrom
HiDeoo:hd/refactor-autogenerated-groups
May 7, 2026
Merged

Refactor autogenerated sidebar groups#3618
delucis merged 24 commits into
withastro:mainfrom
HiDeoo:hd/refactor-autogenerated-groups

Conversation

@HiDeoo
Copy link
Copy Markdown
Member

@HiDeoo HiDeoo commented Dec 9, 2025

Description

This PR removes the notion of "autogenerated sidebar groups" in favor of simply using "autogenerated sidebar links" which can be used in regular sidebar groups. As discussed in #3336, this simplifies the mental model around groups and also allows for use cases that were not possible before, such as having a sidebar entirely made of autogenerated links for a specific directory without having it nested inside a group.

For users, the gist of the change is:

{
    label: 'My group',
-   autogenerate: { directory: 'some-dir' },
+   items: [{ autogenerate: { directory: 'some-dir' } }],
}

Such refactor removes the 1:1 mapping that was previously available between an autogenerated sidebar group in the Starlight configuration and such autogenerated group in the Starlight route data. To address such change, the Starlight route data has been updated and many solutions are possible to address this, e.g. having multiple types (link, autolink, group, and autogroup). This PR has gone through multiple variations of such approach, and the current implementation does not introduce new types but rather adds an autogenerated property set to to true for links and subgroups that were autogenerated. Of course, other approaches are possible and feedback is welcome.

To make sure such change does not impact plugins with previous features that would no longer be possible due to the changes, I rewrote locally the starlight-auto-sidebar plugin, which was heavily relying on that 1:1 mapping and to my knowledge, may be one of the "largest" plugins tweaking sidebar route data for autogenerated groups with a large enough set of tests. I managed to rewrite it successfully while using the Starlight version from this PR and achieved the same results as before.

Note: I also addded a few tests for some behaviors that were not covered before and were impacted by this change, e.g. the collapsed state of autogenerated subgroups.

Remaining tasks

  • Add changeset

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Dec 9, 2025

🦋 Changeset detected

Latest commit: ad5286c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Minor

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

@netlify
Copy link
Copy Markdown

netlify Bot commented Dec 9, 2025

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit ad5286c
🔍 Latest deploy log https://app.netlify.com/projects/astro-starlight/deploys/69fb3c7db5a0080008a79b26
😎 Deploy Preview https://deploy-preview-3618--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added 📚 docs Documentation website changes 🌟 core Changes to Starlight’s main package labels Dec 9, 2025
@astrobot-houston
Copy link
Copy Markdown
Contributor

astrobot-houston commented Dec 9, 2025

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

Locale File Note
en guides/sidebar.mdx Source changed, localizations will be marked as outdated.
en reference/configuration.mdx Source changed, localizations will be marked as outdated.
en reference/frontmatter.md Source changed, localizations will be marked as outdated.
en reference/route-data.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

Comment thread packages/starlight/__tests__/basics/config-errors.test.ts
Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the branch to be aligned with main and noted a few things. Most were notes I can use myself, but one question would be good to get feedback on from you @HiDeoo!

Comment thread docs/src/content/docs/guides/sidebar.mdx Outdated
Comment thread docs/src/content/docs/guides/sidebar.mdx Outdated
Comment thread docs/src/content/docs/guides/sidebar.mdx
Comment thread packages/starlight/__tests__/basics/navigation.test.ts Outdated
Comment thread packages/starlight/__tests__/basics/navigation.test.ts Outdated
Comment thread packages/starlight/utils/routing/types.ts
Comment thread packages/starlight/utils/error-map.ts Outdated
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
@delucis delucis added the 🌟 minor Change that triggers a minor release label Mar 25, 2026
@delucis delucis added this to the v0.39 milestone Mar 25, 2026
@delucis delucis marked this pull request as ready for review March 25, 2026 17:33
Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is in pretty good shape!

There’s this note-to-self #3618 (comment) that you might want to revisit @HiDeoo?

Otherwise, unless you think we should add any additional autogenerate metadata to the sidebar links structure, I’d love to get this out in the next minor release 🚀

@HiDeoo
Copy link
Copy Markdown
Member Author

HiDeoo commented May 5, 2026

Pushed a new update adressing this comment and refactoring the previously exposed autogenerated: boolean property on route data to an autogenerate object with a directory property matching the configured autogenerated directory so we can discuss it with a concrete example.

I also included in a dedicated commit some changes adressing this previous note regarding type error location. I did that in a dedicated commit so it can be easily reverted as I think it may be getting out of hand and trying to fight TypeScript too much to get best possible error and locations. Not sure if the extra complexity is worth for a workaround that took me a few hours to even figure out and implement. We already have what I would qualify as quite good runtime validation with detailed error messages, and even migration steps. It also feels a bit fragile as it's relying on some specific TypeScript behavior that is not guaranteed to be stable.

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates @HiDeoo!

Re: the Typescript stuff — I don’t have too strong an opinion. It’s definitely getting very arcane and hard to understand with these subtle things like void vs never, but I’ll let you decide if you want to keep it or not.

Comment thread packages/starlight/__tests__/basics/navigation-labels.test.ts
Comment thread packages/starlight/utils/navigation.ts Outdated
@HiDeoo
Copy link
Copy Markdown
Member Author

HiDeoo commented May 5, 2026

Pushed a few updates:

  • Removed the TypeScript changes. While it refined the type error locations, I think it made the error even more obscure imo. The never type was already probably confusing but more common than void and could still guessed by just reading the error message. With the refactor, reading that something is "not assignable to type 'void'" felt less intuitive. In the end, I think our runtime error message will provide the best guidance with exact location.

    SCR-20260505-lhnp
  • Updated the configuration reference documentation which was still not updated

  • Documented Astro.locals.starlightRoute.sidebar in the route data reference page. Right now, I just started by inlining everything in details as a base and we can later restructure/shorten/move it if needed.

  • Did some refactor in utils/navigation.ts as pointed out in this comment. I also found some old data that we were still passing around from before sidebar intermediate representations, so I cleaned those up as well.

I also played a bit with the idea of allowing either directory: '.' or directory: '' in the config (not included). After implementing a basic version and actually trying out the directory: '.' option by typing it in my Astro config, I found it more confusing than just using directory: '':

  • . usually refers to the current directory, so while editing the config, my current directory was the project root but the directory we would be autogenerating from is the src/conten/docs/ directory.
  • If . is supported, can I use ..?

Only my opinion of course, and happy to discuss further, but I kept directory: '' for now since it felt more intuitive to me.

Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful work as always @HiDeoo!

I agree that '' for the root directory option works. It feels natural to go from 'dir/sub-dir' => 'dir' => '' and, like you say, this avoids the hint of the relative path syntax meaning current directory and suggesting '..' or './dir' might work.

Left a few comments — mostly pretty minor, although the collapsed question might warrant some discussion?

Comment thread .changeset/00-slow-dragons-notice.md
Comment thread docs/src/content/docs/reference/configuration.mdx Outdated
Comment thread docs/src/content/docs/reference/route-data.mdx Outdated
Comment thread docs/src/content/docs/reference/route-data.mdx
Comment thread packages/starlight/schemas/sidebar.ts
HiDeoo and others added 4 commits May 6, 2026 11:17
Co-authored-by: delucis <357379+delucis@users.noreply.github.com>
Co-authored-by: delucis <357379+delucis@users.noreply.github.com>
Co-authored-by: delucis <357379+delucis@users.noreply.github.com>
Copy link
Copy Markdown
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Seems like a good cleanup indeed.

I think this is looking ready for release! Awesome work figuring out this new approach to make things more flexible for users @HiDeoo 👏

@delucis delucis added the ✅ approved Pull requests that have been approved and are ready to merge when next cutting a release label May 6, 2026
@HiDeoo
Copy link
Copy Markdown
Member Author

HiDeoo commented May 6, 2026

Thanks for the thorough review and super helpful suggestions as always 🙌

@delucis delucis merged commit dcf6d09 into withastro:main May 7, 2026
18 checks passed
@astrobot-houston astrobot-houston mentioned this pull request May 6, 2026
ArmandPhilippot added a commit to ArmandPhilippot/starlight that referenced this pull request May 9, 2026
dadezzz pushed a commit to dadezzz/university_notes that referenced this pull request May 12, 2026
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [@astrojs/starlight](https://starlight.astro.build) ([source](https://github.com/withastro/starlight/tree/HEAD/packages/starlight)) | [`0.38.5` → `0.39.2`](https://renovatebot.com/diffs/npm/@astrojs%2fstarlight/0.38.5/0.39.2) | ![age](https://developer.mend.io/api/mc/badges/age/npm/@astrojs%2fstarlight/0.39.2?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@astrojs%2fstarlight/0.38.5/0.39.2?slim=true) |

---

### Release Notes

<details>
<summary>withastro/starlight (@&#8203;astrojs/starlight)</summary>

### [`v0.39.2`](https://github.com/withastro/starlight/blob/HEAD/packages/starlight/CHANGELOG.md#0392)

[Compare Source](https://github.com/withastro/starlight/compare/@astrojs/starlight@0.39.1...@astrojs/starlight@0.39.2)

##### Patch Changes

- [#&#8203;3890](withastro/starlight#3890) [`2d05e18`](withastro/starlight@2d05e18) Thanks [@&#8203;tats-u](https://github.com/tats-u)! - Fixes CSS selector for `text-autospace` styles in Chromium browsers

### [`v0.39.1`](https://github.com/withastro/starlight/blob/HEAD/packages/starlight/CHANGELOG.md#0391)

[Compare Source](https://github.com/withastro/starlight/compare/@astrojs/starlight@0.39.0...@astrojs/starlight@0.39.1)

##### Patch Changes

- [#&#8203;3885](withastro/starlight#3885) [`010eed1`](withastro/starlight@010eed1) Thanks [@&#8203;ArmandPhilippot](https://github.com/ArmandPhilippot)! - Fixes the version mentioned in an error message related to autogenerated sidebar groups support.

- [#&#8203;3887](withastro/starlight#3887) [`b3c6990`](withastro/starlight@b3c6990) Thanks [@&#8203;delucis](https://github.com/delucis)! - Adds 13 new icons: `clock`, `desktop`, `mobile-android`, `window`, `database`, `server`, `code-branch`, `notes`, `question`, `question-circle`, `analytics`, `padlock`, and `solidjs`.

### [`v0.39.0`](https://github.com/withastro/starlight/blob/HEAD/packages/starlight/CHANGELOG.md#0390)

[Compare Source](https://github.com/withastro/starlight/compare/@astrojs/starlight@0.38.5...@astrojs/starlight@0.39.0)

##### Minor Changes

- [#&#8203;3618](withastro/starlight#3618) [`dcf6d09`](withastro/starlight@dcf6d09) Thanks [@&#8203;HiDeoo](https://github.com/HiDeoo)! - **⚠️ BREAKING CHANGE:** This release changes how autogenerated links work in Starlight’s sidebar configuration.

  If you have sidebar groups using the `autogenerate` key, you must now wrap that configuration in an `items` array:

  ```diff
  {
      label: 'My group',
  -   autogenerate: { directory: 'some-dir' },
  +   items: [{ autogenerate: { directory: 'some-dir' } }],
  }
  ```

  This change unlocks the possibility to mix autogenerated links and other links in a single group, for example:

  ```js
  {
    label: 'Mixed group',
    items: [
      'example-page',
      { autogenerate: { directory: 'examples' } },
      { label: 'More examples', link: 'https://example.com' },
    ],
  }
  ```

  This release also updates the shape of autogenerated sidebar entries in route data. Autogenerated links and groups in `Astro.locals.starlightRoute.sidebar` now include an `autogenerate` object with the [configured `directory` value](https://starlight.astro.build/guides/sidebar/#autogenerated-groups):

  ```js
  {
    type: 'link',
    label: 'Example',
    href: '/examples/example/',
    isCurrent: false,
    autogenerate: { directory: 'examples' }
  }
  ```

- [#&#8203;3618](withastro/starlight#3618) [`dcf6d09`](withastro/starlight@dcf6d09) Thanks [@&#8203;HiDeoo](https://github.com/HiDeoo)! - **⚠️ BREAKING CHANGE:** This release changes the default collapsed state of autogenerated sidebar subgroups.

  Autogenerated subgroups no longer inherit the `collapsed` value from their parent group. They are now expanded by default unless explicitly configured with [`autogenerate.collapsed`](https://starlight.astro.build/reference/configuration/#collapsing-groups).

  If your sidebar configuration relies on a collapsed parent group to also collapse its autogenerated subgroups, update your configuration to set `autogenerate.collapsed` to `true`:

  ```diff
  {
    label: 'Reference',
    collapsed: true,
    items: [
  -   { autogenerate: { directory: 'reference' } },
  +   { autogenerate: { directory: 'reference', collapsed: true } },
    ],
  }
  ```

- [#&#8203;3845](withastro/starlight#3845) [`4d755f5`](withastro/starlight@4d755f5) Thanks [@&#8203;delucis](https://github.com/delucis)! - Adds a `<link rel="alternate" hreflang="x-default" href="...">` tag pointing to the default locale in multilingual sites. The `x-default` alternate is used as a signal of which language to fall back to if no other is available. Learn more in Google’s [SEO localization docs](https://developers.google.com/search/docs/specialty/international/localized-versions#xdefault).

- [#&#8203;3862](withastro/starlight#3862) [`ec70630`](withastro/starlight@ec70630) Thanks [@&#8203;itrew](https://github.com/itrew)! - Makes spacing of items in nested lists more consistent

- [#&#8203;3872](withastro/starlight#3872) [`417a66c`](withastro/starlight@417a66c) Thanks [@&#8203;tats-u](https://github.com/tats-u)! - Enables [the CSS property `text-autospace`](https://developer.mozilla.org/docs/Web/CSS/Reference/Properties/text-autospace) in Chinese and Japanese documents.

  If you would prefer to disable autospacing in Chinese and Japanese pages, you can add the following custom CSS to your site:

  ```css
  [lang]:where(:lang(zh, ja)) {
    text-autospace: initial;
  }
  ```

- [#&#8203;3797](withastro/starlight#3797) [`9764ebd`](withastro/starlight@9764ebd) Thanks [@&#8203;delucis](https://github.com/delucis)! - Avoids the risk of layout shift when users expand and collapse sidebar groups

  This release can introduce additional padding to the site sidebar on certain devices to reserve space for scrollbars. You may wish to inspect your site sidebar visually when upgrading.

  If you would prefer to keep the previous styling, you can add the following custom CSS to your site:

  ```css
  .sidebar-pane {
    scrollbar-gutter: auto;
  }
  ```

- [#&#8203;3858](withastro/starlight#3858) [`6672c35`](withastro/starlight@6672c35) Thanks [@&#8203;delucis](https://github.com/delucis)! - Updates `i18next`, used for Starlight’s localization APIs, from v23 to v26

  There should not be any user-facing changes from this update

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNjAuNyIsInVwZGF0ZWRJblZlciI6IjQzLjE3MC4yMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅ approved Pull requests that have been approved and are ready to merge when next cutting a release 🌟 core Changes to Starlight’s main package 📚 docs Documentation website changes 🌟 minor Change that triggers a minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants