From 09bb6cd8799cd895694f5e3a913fbecc7e010388 Mon Sep 17 00:00:00 2001 From: Limon Monte Date: Mon, 18 Dec 2017 15:02:23 +0200 Subject: [PATCH] fix(FlattenedNodesObserver): do not fail on node without children --- lib/utils/flattened-nodes-observer.html | 4 ++-- test/unit/flattened-nodes-observer.html | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/utils/flattened-nodes-observer.html b/lib/utils/flattened-nodes-observer.html index 78f74127c5..0a291ec248 100644 --- a/lib/utils/flattened-nodes-observer.html +++ b/lib/utils/flattened-nodes-observer.html @@ -130,7 +130,7 @@ connect() { if (isSlot(this._target)) { this._listenSlots([this._target]); - } else { + } else if (this._target.children) { this._listenSlots(this._target.children); if (window.ShadyDOM) { this._shadyChildrenObserver = @@ -159,7 +159,7 @@ disconnect() { if (isSlot(this._target)) { this._unlistenSlots([this._target]); - } else { + } else if (this._target.children) { this._unlistenSlots(this._target.children); if (window.ShadyDOM && this._shadyChildrenObserver) { ShadyDOM.unobserveChildren(this._shadyChildrenObserver); diff --git a/test/unit/flattened-nodes-observer.html b/test/unit/flattened-nodes-observer.html index 27b0190d24..54cdd22604 100644 --- a/test/unit/flattened-nodes-observer.html +++ b/test/unit/flattened-nodes-observer.html @@ -1039,6 +1039,16 @@ document.body.removeChild(host); }); + test('should not fail on node without children', function() { + var recorded; + var el = document; + var observer = new Polymer.FlattenedNodesObserver(el, function(info) { + recorded = info; + }); + assert.equal(recorded, null); + observer.disconnect(); + }); + });