Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Pasting external text no longer works in portable text editor #3532

Closed
theycallmeswift opened this issue Aug 18, 2022 · 22 comments
Closed
Labels

Comments

@theycallmeswift
Copy link

theycallmeswift commented Aug 18, 2022

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)
@skogsmaskin
Copy link
Member

@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

@theycallmeswift
Copy link
Author

@skogsmaskin no problem. Here's the output:

theycallmeswift.dev@0.1.0 /Users/theycallmeswift/dev/theycallmeswift.dev
└─┬ sanity@3.0.0-dev-preview.15
  ├── @sanity/block-tools@3.0.0-dev-preview.15
  └─┬ @sanity/portable-text-editor@3.0.0-dev-preview.15
    └── @sanity/block-tools@3.0.0-dev-preview.15 deduped

theycallmeswift.dev@0.1.0 /Users/theycallmeswift/dev/theycallmeswift.dev
├─┬ sanity-plugin-markdown@3.0.0-v3-studio.0
│ └── sanity@3.0.0-dev-preview.15 deduped
└── sanity@3.0.0-dev-preview.15

@theycallmeswift
Copy link
Author

theycallmeswift commented Aug 18, 2022

@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.

@samwightt
Copy link

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

To reproduce:

  • Clone the repo (git clone git@github.com:bike-grid-now/bike-grid-monorepo).
  • Install deps (pnpm install)
  • Run Sanity Studio in packages/sanity.

@samwightt
Copy link

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.

@jonespen
Copy link

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

image

Dependencies:
image

Reverting to 2.28.2 resolves the issue.

@raulfdm
Copy link
Contributor

raulfdm commented Sep 20, 2022

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

@christiandewit
Copy link

christiandewit commented Sep 23, 2022

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

@austencm
Copy link

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

@chrispecoraro
Copy link
Contributor

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

@vimtor
Copy link

vimtor commented Nov 18, 2022

Same issue here on 2.35.2 using pnpm

@RitaDias RitaDias removed the v3 label Dec 16, 2022
@rexxars rexxars changed the title Pasting external text no longer works in Studio v3 Rich Editor [v3] Pasting external text no longer works in portable text editor Dec 16, 2022
@JannikWempe
Copy link

JannikWempe commented Mar 23, 2023

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.

@andreidragu
Copy link

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)

@harryyaprakov
Copy link

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.

@PetroSilenius
Copy link

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

@skogsmaskin
Copy link
Member

skogsmaskin commented Mar 28, 2023

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.

@barrymay
Copy link

barrymay commented Sep 7, 2023

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"
    }
  },
  ...

@braincomb
Copy link

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

@MartCube
Copy link

MartCube commented Jun 3, 2024

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

@MindDesign
Copy link

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.

@roelvan
Copy link

roelvan commented Jun 7, 2024

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

@braincomb
Copy link

There's a new issue already opened that's tracking this: #6715

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests