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

RichTextEditor image upload (Cannot read properties of null (reading 'index')) #1508

Closed
timahuna opened this issue May 24, 2022 · 5 comments
Closed
Labels
help wanted Contributions from community are welcome

Comments

@timahuna
Copy link

What package has an issue

@mantine/rte

Describe the bug

  1. Wrap react app in a Strict Mode component.
  2. Add a RichTextEditor component.
  3. Add an image via the embed image icon in the toolbar:

image

4. You should see the error `Cannot read properties of null (reading 'index')`

Drag/drop works, pasting works, just the toolbar is causing this error (when wrapped in <StrictMode>).

In which browser did the problem occur

Chrome

If possible, please include a link to a codesandbox with the reproduced problem

https://codesandbox.io/s/bold-field-ilkjez?file=/src/App.js

Do you know how to fix the issue

No

Are you willing to participate in fixing this issue and create a pull request with the fix

No response

Possible fix

Looks like this.range is reset in the ImageUploader in strict mode.

I could be wrong (and I haven't tested this) but I think we might want to set the range here via this.range = this.quill.getSelection();.

@timahuna timahuna added the bug label May 24, 2022
@rtivital rtivital added the help wanted Contributions from community are welcome label May 24, 2022
@wes337
Copy link
Contributor

wes337 commented May 25, 2022

Duplicate of or closely related to #1386

@rtivital
Copy link
Member

Fixed in 4.2.7

@mvskvortsov
Copy link

I'm still have this error on almost all of toolbar button: lists, image... And "addRange(): The given range isn't in document." on other toolbar buttons.

@rtivital rtivital reopened this May 29, 2022
@wes337
Copy link
Contributor

wes337 commented May 30, 2022

I'm still have this error on almost all of toolbar button: lists, image... And "addRange(): The given range isn't in document." on other toolbar buttons.

I'm seeing it on lists too. But it is fixed with images, just make sure you're using at least version 4.2.7

But everything else is fine. What do you mean when you say "almost all of the toolbar button"? I'm also seeing the "index is null" error, and not "addRange()". Could we be talking about different issues?

image

@rtivital
Copy link
Member

The issue happens only in with react strict mode, disable strict mode to fix it. The issue cannot currently be resolved on library side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions from community are welcome
Projects
None yet
Development

No branches or pull requests

4 participants