Skip to content

Commit

Permalink
fix(animations): replace copy of query selector node-list from "sprea…
Browse files Browse the repository at this point in the history
…d" to "for"

For element queries that return sufficiently large NodeList objects, using spread syntax to populate the results array causes a RangeError due to the call stack limit being reached. This commit updates the code to use regular "for" loop instead.

Fixes angular#38551.
  • Loading branch information
basherr committed Nov 25, 2020
1 parent 0451eb0 commit 6f84b7c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/animations/browser/src/render/shared.ts
Expand Up @@ -183,13 +183,22 @@ if (_isNode || typeof Element !== 'undefined') {
_query = (element: any, selector: string, multi: boolean): any[] => {
let results: any[] = [];
if (multi) {
// DO NOT REFACTOR TO USE SPREAD SYNTAX.
// For element queries that return sufficiently large NodeList objects,
// using spread syntax to populate the results array causes a RangeError
// due to the call stack limit being reached. `Array.from` can not be used
// as well, since NodeList is not iterable in IE 11, see
// https://developer.mozilla.org/en-US/docs/Web/API/NodeList
// More info is available in #38551.
const elems = element.querySelectorAll(selector);
for (let i = 0; i < elems.length; i++) {
results.push(elems[i]);
}
} else {
const elm = element.querySelector(selector);
results = elm ? [elm] : [];
if (elm) {
results.push(elm);
}
}
return results;
};
Expand Down

0 comments on commit 6f84b7c

Please sign in to comment.