editor-js / image

Image Block for Editor.js
MIT License
238 stars 289 forks source link

[Bug] Preloader doesn't ensure order of showing or hiding #184

Open orionmiz opened 2 years ago

orionmiz commented 2 years ago

How to reproduce the bug in a custom uploader:

uploader: {
  uploadByFile(file) {
    return new Promise((resolve, reject) => {
      // e.g. checking file size, almost synchronous 
      // Pass a file with a size larger than 1024 (1kb)
      if (file.size > 1024) {
          resolve({ success: 0 });
      } else {
        // ... go on
      }
    });
  },
}

In this case, Preloader is meaninglessly being hidden first by hidePreloader following uploadingFailed,

then shown up by showPreloader following FileReader.onload (because it takes longer than the previous one)

As a result, Preloader keeps appearing despite uploading process is already over.

How to fix the bug:

Promisify FileReader and do upload after awaiting FileReader.onload

I'll send a pull request including the fix commits about this issue.

Hypercubed commented 11 months ago

Hello all... this is still an issue. If a custom uploader rejects before the preview is shown; the preview is not dismissed. https://github.com/editor-js/image/pull/185 seams to fix this. Any chance of getting this PR cleanup and merged?