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 23c36a2 commit ecab8ac
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/animations/browser/src/render/shared.ts
Expand Up @@ -183,7 +183,17 @@ if (_isNode || typeof Element !== 'undefined') {
_query = (element: any, selector: string, multi: boolean): any[] => {
let results: any[] = [];
if (multi) {
results.push(...element.querySelectorAll(selector));
// 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);
if (elm) {
Expand Down

0 comments on commit ecab8ac

Please sign in to comment.