Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Problem uploading multiple files in IE8 + angular - stack overflow (+ solution) #2940

Closed
rikkertkoppes opened this issue Feb 12, 2014 · 1 comment

Comments

@rikkertkoppes
Copy link
Contributor

I encountered a problem using the fileupload component in IE8 with angular. I did not completely isolated the problem, but tracked it back and solved it in our implementation.

The problem lies in the following bit: https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.fileupload.js#L1308

_initDataAttributes: function () {
    var that = this,
        options = this.options;
    // Initialize options set via HTML5 data-attributes:
    $.each(
        $(this.element[0].cloneNode(false)).data(),
        function (key, value) {
            if (that._isRegExpOption(key, value)) {
                value = that._getRegExp(value);
            }
            options[key] = value;
        }
    );
},

In IE8, jquery's data() returns not only data-attributes, but also angulars $scope and the blueimpfileupload itself.

When a file is uploaded, the options object, now containing $scope is deep copied, which results in a stack overflow since $scope contains circular references.

Somehow this only occurred on the second subsequent upload, not on the first. I did not find out why, as the solution below resolves the problem anyway.

I resolved the problem by checking whether the returned fields from data() are actually data-attributes:

_initDataAttributes: function () {
    var that = this,
        options = this.options;
    // Initialize options set via HTML5 data-attributes:
    var clone = $(this.element[0].cloneNode(false));
    $.each(
        clone.data(),
        function (key, value) {
            if (clone[0].getAttribute('data-'+key)) {
                if (that._isRegExpOption(key, value)) {
                    value = that._getRegExp(value);
                }
                options[key] = value;
            }
        }
    );
},
@rikkertkoppes
Copy link
Contributor Author

also relates to #2032

blueimp added a commit that referenced this issue Feb 12, 2014
Fixed IE8 + angular issue which causes a stack overflow. Fixes #2940
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant