sanity icon indicating copy to clipboard operation
sanity copied to clipboard

Pasting external text no longer works in Studio v3 Rich Editor

Open theycallmeswift opened this issue 3 years ago • 7 comments

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)

theycallmeswift avatar Aug 18 '22 03:08 theycallmeswift

@theycallmeswift - thanks for the report. I'm trying to reproduce this, but unable to. Could you please give me the result of:

yarn why @sanity/block-tools && yarn why sanity

(or if you use NPM npm ls @sanity/block-tools && npm ls sanity)

Thanks

skogsmaskin avatar Aug 18 '22 06:08 skogsmaskin

@skogsmaskin no problem. Here's the output:

[email protected] /Users/theycallmeswift/dev/theycallmeswift.dev
└─┬ [email protected]
  ├── @sanity/[email protected]
  └─┬ @sanity/[email protected]
    └── @sanity/[email protected] deduped

[email protected] /Users/theycallmeswift/dev/theycallmeswift.dev
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

theycallmeswift avatar Aug 18 '22 15:08 theycallmeswift

@skogsmaskin I was also having trouble reproducing, but I think I have a working broken example (gist linked below). The gist contains a package.json, sanity.config.ts, and a working and non-working package-lock.json. Make sure you provide a valid project key in the sanity config, but otherwise you should be able to reproduce with just these 3-4 files.

https://gist.github.com/theycallmeswift/e198b738174199224e4dc04014b4b85d

Update:

Here's a fun find: If I don't use the package-lock.json files at all, when I install via npm the editor is broken as described, but when I use yarn it works as expected. My guess is that there's some down tree dependency that's not appropriately locked and yarn/npm handle resolving them differently.

theycallmeswift avatar Aug 18 '22 20:08 theycallmeswift

Hello, we're currently experiencing this in this repo.

To reproduce:

  • Clone the repo (git clone [email protected]:bike-grid-now/bike-grid-monorepo).
  • Install deps (pnpm install)
  • Run Sanity Studio in packages/sanity.

samwightt avatar Sep 11 '22 20:09 samwightt

Update: this happens on this line:

image

blockContent is defined and has a fields property that is an array. The code calls Array.find, passing it a function from @sanity/types. Webpack tries to look up this function (__WEBPACK_IMPORTED_MODULE_0__sanity_types__["isBlockChildrenObjectField"]), but it's undefined. The other imports on the object exist:

image

This is happening in @sanity/block-tools/src/util/blockContentTypeFeatures.ts. I have no clue why the function's getting extracted like that when the source code looks completely different.

samwightt avatar Sep 11 '22 20:09 samwightt

I'm getting the same error in v2.33.2 when pasting text:

image

Dependencies: image

Reverting to 2.28.2 resolves the issue.

jonespen avatar Sep 15 '22 16:09 jonespen

I'm getting the same error in v2.33.2 when pasting text:

image

Dependencies: image

Reverting to 2.28.2 resolves the issue.

the same for me... I thought this was a v3 problem only

raulfdm avatar Sep 20 '22 07:09 raulfdm

Had the same issue. For me going back from v2.33.2 to v2.31.1 solved it.

christiandewit avatar Sep 23 '22 13:09 christiandewit

Deleting node_modules and switching to yarn fixed this for me in 3.0.0-dev-preview.21.

austencm avatar Oct 18 '22 20:10 austencm

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

chrispecoraro avatar Nov 02 '22 16:11 chrispecoraro

Same issue here on 2.35.2 using pnpm

vimtor avatar Nov 18 '22 08:11 vimtor

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.

JannikWempe avatar Mar 23 '23 06:03 JannikWempe

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

[email protected] /Users/andrei.dragu/Workspace/tutorials/sanity-tutorial
└─┬ [email protected]
  ├── @sanity/[email protected]
  └─┬ @sanity/[email protected]
    └── @sanity/[email protected] deduped

[email protected] /Users/andrei.dragu/Workspace/tutorials/sanity-tutorial
└── [email protected]

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)

andreidragu avatar Mar 23 '23 20:03 andreidragu

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.

I am receiving the same error on paste of text in some cases.

Reverting to 3.6.0 fixes it on my end as well.

gluharry avatar Mar 24 '23 19:03 gluharry

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

PetroSilenius avatar Mar 28 '23 11:03 PetroSilenius

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.

skogsmaskin avatar Mar 28 '23 12:03 skogsmaskin

While v3 is surely the way, for anyone who needs it, I was able to work around this on v2 by using latest versions and pointing back to form-builder 2.31.1 on overrides:

In the package.json (in the root one if you have workspaces)

{
  ...
  "dependencies": {
    ...
  },
  "pnpm": {
    "overrides": {
      "@sanity/form-builder": "2.31.1"
    }
  },
  ...

barrymay avatar Sep 07 '23 18:09 barrymay

Is this no longer supported anymore?

I'm trying to paste text into a body in Sanity Studio, and it doesn't work, getting this:

DataTransfer with kind="string" is currently not supported

Using sanity v3.44.0

braincomb avatar Jun 03 '24 03:06 braincomb

Is this no longer supported anymore?

I'm trying to paste text into a body in Sanity Studio, and it doesn't work, getting this:

DataTransfer with kind="string" is currently not supported

Using sanity v3.44.0

I'm experiencing the same issue right now

MartCube avatar Jun 03 '24 09:06 MartCube

Is this no longer supported anymore?

I'm trying to paste text into a body in Sanity Studio, and it doesn't work, getting this:

DataTransfer with kind="string" is currently not supported

Using sanity v3.44.0

Same error here on sanity v3.45.0, trying to paste in plain text.

MindDesign avatar Jun 07 '24 11:06 MindDesign

Same error for me, v3.45.0. Issue should be reopened?

roelvan avatar Jun 07 '24 15:06 roelvan

There's a new issue already opened that's tracking this: https://github.com/sanity-io/sanity/issues/6715

braincomb avatar Jun 07 '24 15:06 braincomb