diff --git a/.changeset/strong-pets-rhyme.md b/.changeset/strong-pets-rhyme.md new file mode 100644 index 000000000000..eea88944f0ff --- /dev/null +++ b/.changeset/strong-pets-rhyme.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Adds support for `.strict()` on content collection schemas when a custom `slug` is present. diff --git a/packages/astro/src/content/utils.ts b/packages/astro/src/content/utils.ts index 804925f0fcef..94421cec4126 100644 --- a/packages/astro/src/content/utils.ts +++ b/packages/astro/src/content/utils.ts @@ -126,7 +126,7 @@ export async function getEntryData( // Use `safeParseAsync` to allow async transforms let formattedError; - const parsed = await (schema as z.ZodSchema).safeParseAsync(entry.unvalidatedData, { + const parsed = await (schema as z.ZodSchema).safeParseAsync(data, { errorMap(error, ctx) { if (error.code === 'custom' && error.params?.isHoistedAstroError) { formattedError = error.params?.astroError; diff --git a/packages/astro/test/fixtures/content-collections/src/content/config.ts b/packages/astro/test/fixtures/content-collections/src/content/config.ts index fbd4e381daab..3d7c3977a47b 100644 --- a/packages/astro/test/fixtures/content-collections/src/content/config.ts +++ b/packages/astro/test/fixtures/content-collections/src/content/config.ts @@ -1,7 +1,8 @@ import { z, defineCollection } from 'astro:content'; const withCustomSlugs = defineCollection({ - schema: z.object({}), + // Ensure schema passes even when `slug` is present + schema: z.object({}).strict(), }); const withSchemaConfig = defineCollection({