weixiyen / jquery-filedrop

jQuery plugin - drag and drop desktop files and POST to a URL to handle files.
958 stars 285 forks source link

RangeError: Maximum call stack size exceeded. #169

Closed zedtux closed 7 years ago

zedtux commented 9 years ago

Hello,

First of all, this is a very nice plugin ! :+1:

I have discovered the following bug:

Given the file field is placed within the HTML element where `filedrop` is applied
When user click the drop zone
Then the error "RangeError: Maximum call stack size exceeded." is raised

The issue is that clicking the HTML element fire the click event of jquery-filedrop AND the click event of the file field.

Moving it out of the dropzone HTML element solve the issue.

boughtonp commented 9 years ago

Have upgraded to latest version from git master and encountering the same issue (it wasn't occurring before).

Different browsers give different errors though, so to help others find this issue...

Firefox too much recursion jquery-migrate-1.2.1.min.js Line 2

IE 11 SCRIPT28: Out of stack space File: jquery-2.0.3.min.js, Line: 5, Column: 8326

With the file field outside the drop-zone, but a button inside that triggers it, the click event still fires twice:

<button class="button btn btn-primary" onclick="$('#file_uploader').click();" type="button">Select Files</button>

The solution to that being to stop the propagation in that onclick event:

onclick="event.stopPropagation();$('#file_uploader').click();"
boughtonp commented 9 years ago

Preventing the original infinite recursion should probably be done by fixing the function on lines 84..86 - to be something like:

this.on('click', function(e){
    if ( e.originalEvent.originalTarget.id == opts.fallback_id )
        return;
  $('#' + opts.fallback_id).trigger(e);
});

(untested)

It might also be useful to have a setting which triggers whether this new on click is called at all:

if ( opts.fallback_click_anywhere === true )
{
    this.on('click', function(e){
        if ( e.originalEvent.originalTarget.id == 'opts.fallback_id' )
            return;
        $('#' + opts.fallback_id).trigger(e);
    });
}

Which would be an easier way to fix the firing twice issue, for anyone with lots of upload controls/buttons but the settings defined in a single place.