sanity: [v3] Pasting external text no longer works in portable text editor

In Sanity Studio v3 you are unable to past test from external sources into the rich text editor. However, you can cut and paste text from within the editor itself as expected. Attempting to paste outside text results in the following error message:

Layout.js:50 TypeError: undefined is not a function
    at Array.find (<anonymous>)
    at blockContentFeatures (schema.ts:31:35)
    at createRuleOptions (usePortableTextEditorValue.ts:25:20)
    at new HtmlDeserializer (withoutPatching.ts:50:57)
    at htmlToBlocks (array.ts:21:24)
    at editor2.insertTextOrHTMLData (ActivateOnFocus.js:190:26)
    at editor2.insertData (ActivateOnFocus.js:228:16)
    at MemberFieldError.js:289:19
    at isEventHandled (index.ts:1585:37)
    at index.ts:1446:18

To Reproduce

Steps to reproduce the behavior:

  1. Create any field that is a block element
  {
    name: "content",
    title: "Content",
    type: "array",
    of: [{ type: "block" }],
  },
  1. Open a new document of the type in Sanity Studio and activate the rich text editor.
  2. Attempt to past in text from any source (e.g. copy a URL from your browser)

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

Loom Recording

Which versions of Sanity are you using?

Run sanity versions in the terminal and copy-paste the result here.

What operating system are you using?

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

@sanity/cli (global)  3.0.0-dev-preview.15 (latest: 2.30.6)
@sanity/image-url                    1.0.1 (up to date)
@sanity/webhook                      2.0.0 (up to date)
sanity                3.0.0-dev-preview.15 (latest: 2.29.3)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 17 (4 by maintainers)

Most upvoted comments

This is now fixed with release of v3.8.0

Thank your for reporting this issue. Sorry for the inconvenience, we have now added a test to avoid this particular problem happening again.

I came here while researching my issue. I can’t paste text into a portable text editor either – and I am also using pnpm.

I see this error: image

I am using "sanity": "3.7.1".

Is there a way to make it work besides switching to npm/yarn?

EDIT: Reverting back to "sanity": "3.6.0" solved the issue for me.

Is there any intention to have this working with pnpm for the 2.x branch, or is yarn still the “official” tool to use?

Faced the same issue when pasting text with line breaks to fields of type Portable Text. Downgrading to sanity 3.7.0 from 3.7.1 fixed it for me

I just created a new project, following https://www.sanity.io/docs/create-a-sanity-project with these properties:

? Project name: sanity-tutorial
Your content will be stored in a dataset that can be public or private, depending on
whether you want to query your content with or without authentication.
The default dataset configuration has a public dataset named "production".
? Use the default dataset configuration? Yes
✔ Creating dataset
? Project output path: /Users/andrei.dragu/Workspace/tutorials/sanity-tutorial
? Select project template Blog (schema)
? Do you want to use TypeScript? Yes
✔ Bootstrapping files from template
✔ Resolving latest module versions
✔ Creating default project files
? Package manager to use for installing dependencies? npm

node version: 18.2.1 and npm ls @sanity/block-tools && npm ls sanity

sanity-tutorial@1.0.0 /Users/andrei.dragu/Workspace/tutorials/sanity-tutorial
└─┬ sanity@3.7.1
  ├── @sanity/block-tools@3.7.1
  └─┬ @sanity/portable-text-editor@3.7.1
    └── @sanity/block-tools@3.7.1 deduped

sanity-tutorial@1.0.0 /Users/andrei.dragu/Workspace/tutorials/sanity-tutorial
└── sanity@3.7.1

and afther npm run dev I get this error when I try to paste any text in a block element

toast error

Uncaught error
Cannot apply deep operations on primitive values. Received patch with type "set" and path "{"_key":"1a3435cf8a13"} that targeted the value "undefined"

console error

Error: Cannot apply deep operations on primitive values. Received patch with type "set" and path "{"_key":"1a3435cf8a13"} that targeted the value "undefined"
    at _primitiveApply (primitive.ts:34:11)
    at _applyPatch (applyPatch.ts:23:10)
    at applyPatch5 (applyPatch.ts:27:15)
    at Array.reduce (<anonymous>)
    at applyAll2 (applyPatch.ts:10:18)
    at ArrayOfObjectsField.tsx:102:24
    at PortableTextInput.tsx:259:20
    at Synchronizer.tsx:74:7
    at invokeFunc (debounce.js:95:19)
    at trailingEdge (debounce.js:144:14)

Same issue here on 2.35.2 using pnpm