diff --git a/src/js/abstract/base-component.js b/src/js/abstract/base-component.js index 9162024141..9c723bbc69 100644 --- a/src/js/abstract/base-component.js +++ b/src/js/abstract/base-component.js @@ -1,4 +1,4 @@ -import nanomorph from 'nanomorph'; +import nanomorph from './component-morph'; import getAttribute from '../get-attribute'; import toProp from '../to-prop'; import { publish, subscribe } from '../pubsub'; @@ -398,17 +398,6 @@ export default class BaseComponent extends HTMLElement { this.render(); } - /** - * Monkey patch `childNodes` API to re-rendering. - */ - get childNodes() { - if (this._isMorphing || !this._hasTemplate || !this._hasRendered) { - return super.childNodes; - } - - return []; - } - /** * Monkey patch `appendChild` API to re-rendering. * @@ -425,6 +414,15 @@ export default class BaseComponent extends HTMLElement { this.render(); } + /** + * Only morph children of current custom element, not any other custom element. + * + * @returns {boolean} + */ + skipChildren() { + return !this._isMorphing; + } + // @TODO: atm no data can be shared by enabling context, though this could be necessary /** * Provides an opt-in contextual scope for hierarchy-agnostic child components. diff --git a/src/js/abstract/component-morph.js b/src/js/abstract/component-morph.js index 4936edfca9..4b908481ed 100644 --- a/src/js/abstract/component-morph.js +++ b/src/js/abstract/component-morph.js @@ -59,7 +59,11 @@ function walk(newNode, oldNode) { } morph(newNode, oldNode); - updateChildren(newNode, oldNode); + + if (!oldNode.skipChildren && !oldNode.skipChildren()) { + updateChildren(newNode, oldNode); + } + return oldNode; }