diff options
author | Sgal Cheung | 2025-06-13 17:32:05 +0800 |
---|---|---|
committer | GitHub | 2025-06-13 11:32:05 +0200 |
commit | 95d124ae99f207afd83f305943fa29df32cbbfc9 (patch) | |
tree | b4685a88e34ac28222cf054e269f3eef5e26c9c4 | |
parent | f04316e9e9de1684009b24f869b7e09b91f6630b (diff) | |
download | IT.starlight-95d124ae99f207afd83f305943fa29df32cbbfc9.tar.gz IT.starlight-95d124ae99f207afd83f305943fa29df32cbbfc9.tar.bz2 IT.starlight-95d124ae99f207afd83f305943fa29df32cbbfc9.zip |
fix userCollections?.docs (#3205)
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
Co-authored-by: HiDeoo <494699+HiDeoo@users.noreply.github.com>
-rw-r--r-- | .changeset/lemon-tips-end.md | 5 | ||||
-rw-r--r-- | packages/starlight/__tests__/basics/starlight-page-route-data.test.ts | 14 | ||||
-rw-r--r-- | packages/starlight/utils/starlight-page.ts | 2 |
3 files changed, 20 insertions, 1 deletions
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 `<StarlightPage>` 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<ContentConfig['collections']['docs']['schema']> > { const userCollections = (await import('virtual:starlight/collection-config')).collections; - return userCollections?.docs.schema ?? docsSchema(); + return userCollections?.docs?.schema ?? docsSchema(); } |