withastro / starlight

🌟 Build beautiful, accessible, high-performance documentation websites with Astro
https://starlight.astro.build
MIT License
5.03k stars 532 forks source link

Passing a `frontmatter` containing type `reference()` causes an error in pages that use the `<StarlightPage />` component. #2270

Closed zhoushengdao closed 2 months ago

zhoushengdao commented 2 months ago

What version of starlight are you using?

0.26.1

What version of astro are you using?

4.15.1

What package manager are you using?

pnpm@9.9.0

What operating system are you using?

Windows

What browser are you using?

Edge, Chrome, Firefox

Describe the Bug

Passing a frontmatter containing type reference() causes an error in pages that use the <StarlightPage /> component.

image

Clone the repository, run the pnpm dev command, and then go to http://localhost:4321/page/ to see the error.

Reconstructive process: https://github.com/zhoushengdao/starlight-page-reference-error/commit/6fe29cb0b48cf1ff4df60533c0707103aea9802e

Link to Minimal Reproducible Example

https://github.com/zhoushengdao/starlight-page-reference-error

Participation

HiDeoo commented 2 months ago

Thanks for the report.

I can confirm that I can reproduce the issue but only when using Astro >=4.14.0. By quickly looking at the changelog and considering this version is the one that introduced experimental support for the Content Layer API, I'm assuming so far that this could be potentially related to the issue.

I assume a potential fix could be to always use safeParseAsync for the frontmatter in this specific case (our parseWithFriendlyErrors always uses safeParse at the moment) altho I think we may want first to investigate a bit more to figure out the real root cause of the issue and see if it's an expected change or not.

In the meantime, switching back to Astro 4.13.4 should be a workaround to avoid the issue.

delucis commented 2 months ago

Fairly sure it would be caused by this change: https://github.com/withastro/astro/blame/a79a8b0230b06ed32ce1802f2a5f84a6cf92dbe7/packages/astro/src/content/runtime.ts#L585-L592

I think we can work around it, but will also flag it with the core team.