fix: deduplicate shared block/inline object names in schema compilation#2198
Merged
christianhg merged 1 commit intomainfrom Feb 18, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: 2e3774e The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
a740788 to
e703e4e
Compare
e703e4e to
66b3285
Compare
66b3285 to
a0c4cb0
Compare
a0c4cb0 to
2e3774e
Compare
Merged
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.
Problem
When a type name appears in both
blockObjectsandinlineObjectsof aSchemaDefinition,compileSchemaDefinitionToPortableTextMemberSchemaTypes()passes duplicate type names toSanitySchema.compile(), causing:This happens in Studio when a Sanity schema has an object type used as both a block-level object and an inline object (e.g.,
simpleBlock.tsxin the test studio hasmyStringTypenamed'test'used in both positions).The round-trip path is:
sanitySchemaToPortableTextSchema(schemaType)→ returnsSchemawith separateblockObjectsandinlineObjectsarraysEditorProviderreceives this asschemaDefinitionand callscompileSchemaDefinitionToPortableTextMemberSchemaTypes()defineType({name: 'test'})for both the block object AND the inline objectSanitySchema.compile({types: [...blockObjects, ...inlineObjects]})→ duplicate name errorFix
Generalized the existing temporary-name pattern (previously only handling
imageandurlbuilt-in names) to dynamically detect ANY name that appears in bothblockObjectsandinlineObjects. Shared names get unique temporary names (tmp-<key>-<name>) beforeSanitySchema.compile(), then are mapped back to their original names in the post-compilation fixup.Test cases
handles type appearing in both blockObjects and inlineObjects— verifies a type named'test'in both positions compiles without error and produces correct outputback and forth with shared blockObject and inlineObject names— verifies the full round-trip (Schema→PortableTextMemberSchemaTypes→Schema) preserves shared names correctlyRelated
schemaDefinitionprop (blocked by this bug)@sanity/*dependencies #2136 — removes@sanity/*deps from editor