From 970cff1fa42e973318cd1c36be0bf2c5bbeeb4b5 Mon Sep 17 00:00:00 2001 From: Basheer Ahmed Date: Thu, 12 Nov 2020 16:37:26 +0500 Subject: [PATCH] fix(animations): replace copy of query selector node-list from "spread" 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 #38551. --- packages/animations/browser/src/render/shared.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/animations/browser/src/render/shared.ts b/packages/animations/browser/src/render/shared.ts index 683c009424da6..e2040f9aa15d2 100644 --- a/packages/animations/browser/src/render/shared.ts +++ b/packages/animations/browser/src/render/shared.ts @@ -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; };