Skip to content

Commit 09bb6cd

Browse files
author
Limon Monte
committed
fix(FlattenedNodesObserver): do not fail on node without children
1 parent 8196483 commit 09bb6cd

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/utils/flattened-nodes-observer.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
connect() {
131131
if (isSlot(this._target)) {
132132
this._listenSlots([this._target]);
133-
} else {
133+
} else if (this._target.children) {
134134
this._listenSlots(this._target.children);
135135
if (window.ShadyDOM) {
136136
this._shadyChildrenObserver =
@@ -159,7 +159,7 @@
159159
disconnect() {
160160
if (isSlot(this._target)) {
161161
this._unlistenSlots([this._target]);
162-
} else {
162+
} else if (this._target.children) {
163163
this._unlistenSlots(this._target.children);
164164
if (window.ShadyDOM && this._shadyChildrenObserver) {
165165
ShadyDOM.unobserveChildren(this._shadyChildrenObserver);

test/unit/flattened-nodes-observer.html

+10
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,16 @@
10391039
document.body.removeChild(host);
10401040
});
10411041

1042+
test('should not fail on node without children', function() {
1043+
var recorded;
1044+
var el = document;
1045+
var observer = new Polymer.FlattenedNodesObserver(el, function(info) {
1046+
recorded = info;
1047+
});
1048+
assert.equal(recorded, null);
1049+
observer.disconnect();
1050+
});
1051+
10421052
});
10431053

10441054
</script>

0 commit comments

Comments
 (0)