Skip to content
This repository was archived by the owner on Feb 3, 2026. It is now read-only.

Portable Text fields throw "Attempt to apply insert patch to non-array value" when pasting content #104

@wiiiimm

Description

@wiiiimm

Describe the bug

When using Portable Text fields (block content) with sanity-plugin-internationalized-array, pasting content into an empty field throws an error:

Error: Attempt to apply insert patch to non-array value

This happens specifically when:

  1. The field is wrapped with internationalizedArray
  2. The field type is a Portable Text array field (e.g., body, htmlContent)
  3. The field is empty and you try to paste content into it

Root Cause

The plugin doesn't properly initialize the nested value field as an empty array for Portable Text fields. When Sanity's Portable Text editor tries to apply an InsertPatch operation to paste content, it expects an array but finds undefined or a non-array value.

To Reproduce

  1. Create a schema with an internationalized Portable Text field:
defineField({
  name: 'body',
  title: 'Body',
  type: 'internationalizedArrayBody',
  group: 'editorial',
})
  1. Open a document with this field in Sanity Studio
  2. Try to paste any content into the empty Portable Text editor
  3. See error: "Attempt to apply insert patch to non-array value"

Expected behavior

The Portable Text field should accept pasted content without errors, just like non-internationalized Portable Text fields do.

Workaround Attempts

Tried several workarounds without success:

  • Adding initialValue to set empty arrays
  • Creating wrapper components to intercept and fix patches
  • Attempting to monkey-patch InsertPatch.apply

Which versions of Sanity are you using?

  • sanity: 3.62.3
  • sanity-plugin-internationalized-array: 3.1.5

What operating system are you using?

macOS

Which versions of Node.js / npm are you running?

  • Node: v20.11.1
  • pnpm: 9.12.3

Additional context

This is a critical issue for content editors who rely on copy-paste workflows. The issue occurs specifically with array-based field types (Portable Text) when they're wrapped by the internationalized array plugin.

The fix likely needs to ensure that when a language tab is selected, the value field for array-based content types is properly initialized as an empty array [] rather than undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions