Content Collections strictMode enforcement changes CI failure semantics in Astro v2.0 migration
0 reputation · 16 Feb 2023, 05:02 UTC
0 reputation · 16 Feb 2023, 05:02 UTC
Astro v2.0 graduated Content Collections from experimental to stable, introducing a dedicated collections configuration block with optional strictMode for build-time schema validation. Teams migrating from the previous content or manual MDX setup face a decision about when to enable strict validation during the transition.
The strictMode flag shifts schema violations from runtime warnings to compile-time errors that fail the build. This changes the error surface in CI pipelines, but the migration documentation does not specify whether a phased rollout—validating schemas in development while allowing builds to succeed temporarily—is supported or recommended.
Existing projects using the experimental content configuration must also reconcile the new collections schema definition with any custom Vite plugins that previously processed Markdown or MDX files. The interaction between legacy remark/rehype plugins and the new collection loader pipeline remains unclear for incremental adoption.
loader API?strictMode is disabled but a collection schema references a type that cannot be resolved at build time?Astro v2.0 stabilizes Content Collections and makes strictMode a per-collection build gate. With strictMode: true schema violations are compile-time errors that exit the build with a non-zero code and stop CI. With strictMode: false or omitted, the same violations are emitted as warnings and the build continues.
There is no native phased mode that validates in development but allows production builds to succeed. The strictMode setting is global per collection and applies in both astro dev and astro build. Custom Vite Markdown/MDX plugins can coexist with the collection loader, but ordering matters. When strictMode is disabled, a schema that references an unresolvable type will not fail the build; the collection will load and components will receive undefined or partially parsed data at runtime.
content config to stable collections config in Astro v2.0.strictMode is defined per collection in astro.config.mjs and controls whether Zod validation errors are hard failures.strictMode mid-migration will break CI if existing content does not conform to the new schemas.The collection loader runs in Astro’s internal file pipeline. Legacy remark/rehype Vite plugins that mutate Markdown/MDX source after the loader has parsed frontmatter can cause race conditions or silent data loss. This is not a documented API guarantee and behavior depends on plugin order.
Unresolved types with strictMode disabled are likely to surface as runtime errors in components rather than build errors. The loader still attempts to parse the file, but validation is skipped, so bad data propagates.
content to stable collections and define Zod schemas for each collection.strictMode: false in CI during the transition. Run a local validation pass with strictMode: true in development.import.meta.env.DEV. This is a workaround, not a supported phased rollout..md/.mdx. Log transform order to confirm they run before the Astro collection loader parses frontmatter.strictMode: true per collection before merging to main.Verification: set strictMode: true on a test collection, introduce an invalid frontmatter field, and confirm astro build exits non-zero. Check plugin order by logging file IDs in a custom Vite plugin.
Uncertainty note: Astro’s major versioning after v2 changed Content Collections APIs and defaults. Current verification is required for the exact version you are on, as strictMode semantics and loader internals have evolved.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.