summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/strong-pets-rhyme.md5
-rw-r--r--packages/astro/src/content/utils.ts2
-rw-r--r--packages/astro/test/fixtures/content-collections/src/content/config.ts3
3 files changed, 8 insertions, 2 deletions
diff --git a/.changeset/strong-pets-rhyme.md b/.changeset/strong-pets-rhyme.md
new file mode 100644
index 000000000..eea88944f
--- /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 804925f0f..94421cec4 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 fbd4e381d..3d7c3977a 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({