Skip to content

Comments

fix: deduplicate shared block/inline object names in schema compilation#2198

Merged
christianhg merged 1 commit intomainfrom
fix/deduplicate-shared-block-inline-object-names
Feb 18, 2026
Merged

fix: deduplicate shared block/inline object names in schema compilation#2198
christianhg merged 1 commit intomainfrom
fix/deduplicate-shared-block-inline-object-names

Conversation

@christianhg
Copy link
Member

Problem

When a type name appears in both blockObjects and inlineObjects of a SchemaDefinition, compileSchemaDefinitionToPortableTextMemberSchemaTypes() passes duplicate type names to SanitySchema.compile(), causing:

Error: Duplicate type name added to schema: <name>

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.tsx in the test studio has myStringType named 'test' used in both positions).

The round-trip path is:

  1. Studio calls sanitySchemaToPortableTextSchema(schemaType) → returns Schema with separate blockObjects and inlineObjects arrays
  2. EditorProvider receives this as schemaDefinition and calls compileSchemaDefinitionToPortableTextMemberSchemaTypes()
  3. That function creates defineType({name: 'test'}) for both the block object AND the inline object
  4. Both get passed to SanitySchema.compile({types: [...blockObjects, ...inlineObjects]})duplicate name error

Fix

Generalized the existing temporary-name pattern (previously only handling image and url built-in names) to dynamically detect ANY name that appears in both blockObjects and inlineObjects. Shared names get unique temporary names (tmp-<key>-<name>) before SanitySchema.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 output
  • back and forth with shared blockObject and inlineObject names — verifies the full round-trip (SchemaPortableTextMemberSchemaTypesSchema) preserves shared names correctly

Related

@changeset-bot
Copy link

changeset-bot bot commented Feb 18, 2026

🦋 Changeset detected

Latest commit: 2e3774e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@portabletext/sanity-bridge Patch
@portabletext/block-tools Patch
@portabletext/editor Patch
@portabletext/plugin-character-pair-decorator Patch
@portabletext/plugin-emoji-picker Patch
@portabletext/plugin-input-rule Patch
@portabletext/plugin-markdown-shortcuts Patch
@portabletext/plugin-one-line Patch
@portabletext/plugin-paste-link Patch
@portabletext/plugin-sdk-value Patch
@portabletext/plugin-typeahead-picker Patch
@portabletext/plugin-typography Patch
@portabletext/toolbar Patch

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

@vercel
Copy link

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
portable-text-editor-documentation Ready Ready Preview, Comment Feb 18, 2026 10:13am
portable-text-example-basic Ready Ready Preview, Comment Feb 18, 2026 10:13am
portable-text-playground Ready Ready Preview, Comment Feb 18, 2026 10:13am

Request Review

@christianhg christianhg force-pushed the fix/deduplicate-shared-block-inline-object-names branch from a740788 to e703e4e Compare February 18, 2026 10:02
@christianhg christianhg force-pushed the fix/deduplicate-shared-block-inline-object-names branch from e703e4e to 66b3285 Compare February 18, 2026 10:03
@christianhg christianhg force-pushed the fix/deduplicate-shared-block-inline-object-names branch from 66b3285 to a0c4cb0 Compare February 18, 2026 10:07
@christianhg christianhg force-pushed the fix/deduplicate-shared-block-inline-object-names branch from a0c4cb0 to 2e3774e Compare February 18, 2026 10:12
@christianhg christianhg changed the title fix(sanity-bridge): deduplicate shared block/inline object names in schema compilation fix: deduplicate shared block/inline object names in schema compilation Feb 18, 2026
@christianhg christianhg marked this pull request as ready for review February 18, 2026 10:14
@christianhg christianhg enabled auto-merge (rebase) February 18, 2026 10:16
@christianhg christianhg merged commit 5f1b1fb into main Feb 18, 2026
15 checks passed
@christianhg christianhg deleted the fix/deduplicate-shared-block-inline-object-names branch February 18, 2026 10:16
@ecoscript ecoscript bot mentioned this pull request Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant