fix(content): declare zod as optional peer dependency (#622)#625
Merged
Conversation
Resolves #622. defineOgImageSchema() built the ogImage field with og-image's bundled zod. When that differs from the project's zod (e.g. og-image on zod 4, @nuxt/content on zod 3), Content's per-collection type inference over the foreign-instance schema collapses and ogImage drops off ContentCollectionItem. Passing the project's own instance via defineOgImageSchema({ z }) keeps the whole schema on one zod version so the field is inferred. This is the same remedy nuxtseo-shared's own version-mismatch warning recommends.
commit: |
The real fix for #622. zod was a hard dependency pinned to v4, so og-image forced its own zod copy into the user's tree even when @nuxt/content resolved zod 3. Content builds collection types from the schema object, and a foreign zod-instance ogImage field fails to convert, dropping it from the generated ContentCollectionItem. Move zod to an optional peer dependency (>=3), matching @nuxtjs/sitemap, @nuxtjs/robots and nuxt-schema-org. og-image now resolves the project's own zod instance, so defineOgImageSchema() works by default. Reframe the docs to show the default usage with { z } as a fallback for multi-version trees, and keep it in devDependencies for the repo's own build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
Resolves #622
❓ Type of change
📚 Description
Property 'ogImage' does not exist on type 'ContentCollectionItem'(regressed in v6.5.1).Root cause: zod was a hard
dependencypinned to v4, but it's only used by the Content integration (src/content.ts). That forced og-image's own zod 4 copy into the user's tree even when@nuxt/contentresolved zod 3. Content builds each collection's TS type from the schema object (zod → JSON Schema viazodToJsonSchema→ interface viajson-schema-to-typescript-lite), and that converter only understands one zod version's internals. A foreign-instanceogImagesub-schema fails to convert, so the field drops off the generatedContentCollectionItem.Fix: move zod to an optional
peerDependency(>=3), matching the rest of the SEO ecosystem (@nuxtjs/sitemap,@nuxtjs/robots,nuxt-schema-orgall do this). og-image now resolves the project's single zod instance, sodefineOgImageSchema()works by default with no extra config. Kept indevDependenciesfor the repo's own build.Docs reframed to show the default usage, with
defineOgImageSchema({ z })documented as a fallback for projects that have multiple zod versions installed.Note for the reporter: the typed access path is
queryCollection('content').path(...).first()(per-collection types).useContent()returns the broad cross-collection base type and may still not surfaceogImage.