From e95cd2a17a169ee4e8ec0a267d897cf39591d87e Mon Sep 17 00:00:00 2001 From: Basheer Ahmed Date: Thu, 12 Nov 2020 15:37:09 +0500 Subject: [PATCH] fix(animations): replace copy of query selector node-list from "spread" to "for" (#39646) 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 #38551. PR Close #39646 --- packages/animations/browser/src/render/shared.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/animations/browser/src/render/shared.ts b/packages/animations/browser/src/render/shared.ts index 40d9085a950ce..e2040f9aa15d2 100644 --- a/packages/animations/browser/src/render/shared.ts +++ b/packages/animations/browser/src/render/shared.ts @@ -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) {