question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@mantine/rte 4.2.8 onImageUpload not handling image properly

See original GitHub issue

What package has an issue

@mantine/rte

Describe the bug

The image upload functionality seems to work fine whenever I don’t supply a function to onImageUpload, but when I have a function provided that uploads the file to storage and returns the url the RTE component does not render the image and also won’t allow me to insert new lines when typing text by hitting enter.

Here’s my component:

            <RichTextEditor
              value={content}
              style={{ listStyleType: "disc" }}
              classNames={{
                root: "min-h-[280px]",
                toolbar: "!static",
              }}
              onChange={setContent}
              modules={modules}
              controls={richTextControls}
              onImageUpload={handleImageUpload}
              mentions={mentions}
            />

and my handleImageUpload function:

const handleImageUpload = (file: File): Promise<string> =>
    new Promise((resolve, reject) => {
      supabase.storage
        .from("BUCKET_NAME")
        .upload(`${teamId}/${file.name}`, file, {
          cacheControl: "3600",
          upsert: true,
        })
        .then(() => {
          const { publicURL } = supabase.storage
            .from("BUCKET_NAME")
            .getPublicUrl(`${teamId}/${file.name}`);
          resolve(publicURL!);
        })
        .catch(() => reject(new Error("upload failed")));
    });

I’ve replaced the actual bucket name with a placeholder. I’ve also console logged the url prior to resolve and confirmed that it’s getting the actual url string as expected, so I’m not sure what’s happening. As soon as I comment out the “onImageUploads” prop of the RTE component everything works fine (aside from not being able to save my file).

I’ve also noticed that when I have onImageUploads set to a function (even a dummy function that returns just a Promise with a placeholder string) I’m getting “addRange(): The given range isn’t in document.” with every keystroke when typing in the editor and the enter key no longer inserts newlines.

Any help with this would be greatly appreciated, thank you for all the hard work in building and maintaining this project!

In which browser did the problem occur

Chrome

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

No response

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

Yes

Possible fix

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wes337commented, Jun 12, 2022

There was recently a problem similar to this, and it was solved when the handleImageUpload function was wrapped in a useCallback hook.

0reactions
rtivitalcommented, Jun 13, 2022

Yep, I think we can add useCallback to the documentation

Read more comments on GitHub >

github_iconTop Results From Across the Web

mantine/rte 4.2.8 onImageUpload not handling image properly
The image upload functionality seems to work fine whenever I don't supply a function to onImageUpload, but when I have a function provided...
Read more >
summernote upload image: onImageUpload and sendFile ...
It seems that the summernote page is not passing any info to the editor-upload2.php file because nothing is getting uploaded and nothing is ......
Read more >
@mantine/rte: Versions | Openbase
Full version history for @mantine/rte including change logs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found