Skip to content

fix: broaden usePortableTextEditor().schemaTypes type for backward compatibility#2296

Closed
christianhg wants to merge 1 commit intomainfrom
feat/schema-compat-types
Closed

fix: broaden usePortableTextEditor().schemaTypes type for backward compatibility#2296
christianhg wants to merge 1 commit intomainfrom
feat/schema-compat-types

Conversation

@christianhg
Copy link
Member

When PTE depended on @sanity/types, usePortableTextEditor().schemaTypes returned types that included Sanity-specific properties like icon, component, and i18nTitleKey. Consumers (especially toolbar implementations) accessed these properties to render icons and custom components.

After v6 removed the @sanity/types dependency, these properties disappeared from the type, causing type errors for consumers that accessed them.

This PR adds a PortableTextEditorSchemaTypes type in @portabletext/editor that extends the clean PTE-native schema types with optional Sanity-compatible properties. The @portabletext/schema package is untouched - the broadening only happens at the PortableTextEditor.schemaTypes property.

The optional properties are:

  • icon?: unknown - toolbar icons (was ReactNode | ComponentType)
  • component?: unknown - custom render components (was ComponentType<...>)
  • i18nTitleKey?: string - i18n title keys

These are typed as unknown (or string for i18nTitleKey) because PTE itself does not populate them. They may be present when the schema originates from a Sanity schema via @portabletext/sanity-bridge. Consumers doing if (decorator.icon) will get no type error and the truthiness check will correctly skip the branch when the value is undefined.

For block and span, the type uses & {[key: string]: unknown} to allow arbitrary property access without type errors, since the old ObjectSchemaType from @sanity/types had many properties.

Files changed

  • packages/editor/src/types/schema-compat.ts - new file with PortableTextEditorSchemaTypes type
  • packages/editor/src/editor/PortableTextEditor.tsx - use broader type for schemaTypes
  • packages/editor/src/index.ts - export the new type

…mpatibility

Add optional Sanity-compatible properties (icon, component, i18nTitleKey) to
the schema types returned by usePortableTextEditor().schemaTypes. This eases
migration for consumers that previously accessed these properties when PTE
depended on @sanity/types.

The PTE-native Schema type in @portabletext/schema remains clean. The broader
PortableTextEditorSchemaTypes type lives in @portabletext/editor and is only
used for the deprecated PortableTextEditor class.
@vercel
Copy link

vercel bot commented Mar 3, 2026

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

Project Deployment Actions Updated (UTC)
portable-text-example-basic Building Building Preview, Comment Mar 3, 2026 2:43pm
portable-text-playground Building Building Preview, Comment Mar 3, 2026 2:43pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2026

⚠️ No Changeset found

Latest commit: 5f8521c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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