From 95d124ae99f207afd83f305943fa29df32cbbfc9 Mon Sep 17 00:00:00 2001 From: Sgal Cheung Date: Fri, 13 Jun 2025 17:32:05 +0800 Subject: fix userCollections?.docs (#3205) Co-authored-by: Chris Swithinbank Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com>--- .changeset/lemon-tips-end.md | 5 +++++ .../__tests__/basics/starlight-page-route-data.test.ts | 14 ++++++++++++++ packages/starlight/utils/starlight-page.ts | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .changeset/lemon-tips-end.md diff --git a/.changeset/lemon-tips-end.md b/.changeset/lemon-tips-end.md new file mode 100644 index 00000000..fe4d7192 --- /dev/null +++ b/.changeset/lemon-tips-end.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Fixes an issue preventing to use the `` component when the `docs` content collection that Starlight uses does not exist. diff --git a/packages/starlight/__tests__/basics/starlight-page-route-data.test.ts b/packages/starlight/__tests__/basics/starlight-page-route-data.test.ts index 2c5f5363..bd9e1707 100644 --- a/packages/starlight/__tests__/basics/starlight-page-route-data.test.ts +++ b/packages/starlight/__tests__/basics/starlight-page-route-data.test.ts @@ -610,3 +610,17 @@ test('fails to parse an image without the expected metadata properties', async ( > Received \`{}\`" `); }); + +test('adds data to route shape when the `docs` collection is not defined', async () => { + // Mock the collection config in this test to simulate the absence of the `docs` collection. + vi.doMock('virtual:starlight/collection-config', () => ({ collections: {} })); + + const data = await generateStarlightPageRouteData({ + props: starlightPageProps, + context: getRouteDataTestContext(starlightPagePathname), + }); + expect(data.entry.data.title).toBe(starlightPageProps.frontmatter.title); + + // Undo the mock to restore the original behavior. + vi.doUnmock('virtual:starlight/collection-config'); +}); diff --git a/packages/starlight/utils/starlight-page.ts b/packages/starlight/utils/starlight-page.ts index 01fe7dd7..3f0ba6b9 100644 --- a/packages/starlight/utils/starlight-page.ts +++ b/packages/starlight/utils/starlight-page.ts @@ -211,5 +211,5 @@ async function getUserDocsSchema(): Promise< NonNullable > { const userCollections = (await import('virtual:starlight/collection-config')).collections; - return userCollections?.docs.schema ?? docsSchema(); + return userCollections?.docs?.schema ?? docsSchema(); } -- cgit