diff --git a/CHANGELOG.md b/CHANGELOG.md index 79f30f27f..f7270b332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## Unreleased +- FlattenedNodesObserver.getFlattenedNodes was accidentally quadratic if given a non-slot node. Found by @mvanbem-goog. + ## [v3.5.1](https://github.com/Polymer/polymer/tree/v3.5.1) (2022-06-03) - [ci skip] bump to 3.5.1 ([commit](https://github.com/Polymer/polymer/commit/2cbb3d2b)) diff --git a/lib/utils/flattened-nodes-observer.js b/lib/utils/flattened-nodes-observer.js index 920ef9a6f..24a5156ba 100644 --- a/lib/utils/flattened-nodes-observer.js +++ b/lib/utils/flattened-nodes-observer.js @@ -88,14 +88,17 @@ export let FlattenedNodesObserver = class { node = /** @type {!HTMLSlotElement} */(node); // eslint-disable-line no-self-assign return wrapped.assignedNodes({flatten: true}); } else { - return Array.from(wrapped.childNodes).map((node) => { + const results = []; + for (let i = 0; i < wrapped.childNodes.length; i++) { + const node = wrapped.childNodes[i]; if (isSlot(node)) { - node = /** @type {!HTMLSlotElement} */(node); // eslint-disable-line no-self-assign - return wrap(node).assignedNodes({flatten: true}); + const slotNode = /** @type {!HTMLSlotElement} */ (node); + results.push(...wrap(slotNode).assignedNodes({ flatten: true })); } else { - return [node]; + results.push(node); } - }).reduce((a, b) => a.concat(b), []); + } + return results; } } @@ -311,4 +314,4 @@ export let FlattenedNodesObserver = class { } } -}; \ No newline at end of file +};