image icon indicating copy to clipboard operation
image copied to clipboard

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

Open orionmiz opened this issue 2 years ago • 1 comments

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.

orionmiz avatar Jun 05 '22 04:06 orionmiz