evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
37.58k stars 1.11k forks source link

Minified code performs differently for opening a file browser #3810

Closed mangelozzi closed 1 week ago

mangelozzi commented 1 week ago

This code:

/*
    @multiple - Boolean
    @accept - String
        A comma separated list of accetable extensions, e.g. ".pdf,.jpg,.jpeg,.png,.gif,.doc,.docx"
*/
export function selectFile(multiple, accept, setFileCb) {
    async function runSelectFile(event) {
        // Step 2. Upload the files then delete the file input so its not posted
        let fileInput = event.target;
        const files = fileInput.files; // If multiple attribute was set, files will be a single file
        fileInput.remove();
        applyFileCallback(files, multiple, setFileCb);
    }
    // Step 1. Create a temporary input[type="file] widget and click it
    let fileInput = document.createElement('input');
    fileInput.type = 'file';
    multiple && fileInput.setAttribute('multiple', '');
    accept && fileInput.setAttribute('accept', accept);
    fileInput.addEventListener('change', runSelectFile.bind(this));
    fileInput.click();
}

Could be used like this:

import { selectFile } from '/your/own/path.js';
    selectFile(false, '.jpg,.jpeg,.png,.gif', (file) => console.log(file))

When you run function it bring up the file browser selection, however the minified version, it opens the file browser rwice in chrome. So one selects the file, then the file browser pops up again and one has to cancel it the second time:

export function selectFile(e,n,r){async function i(o){let l=o.target;const g=l.files;l.remove(),s(g,e,r)}let t=document.createElement("input");t.type="file",e&&t.setAttribute("multiple",""),n&&t.setAttribute("accept",n),t.addEventListener("change",i.bind(this)),t.click()}
mangelozzi commented 1 week ago

I think this issue is invalid, further testing shows this issue is invalid