Skip to content

Commit

Permalink
src: Move isInDocument higher up stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Aug 18, 2020
1 parent befce08 commit 7dd337e
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class Tonic extends window.HTMLElement {
if (this.pendingReRender) return this.pendingReRender

this.pendingReRender = new Promise(resolve => window.setTimeout(() => {
if (!this.isInDocument(this.shadowRoot || this)) return
const p = this._set(this.shadowRoot || this, this.render)
this.pendingReRender = null

Expand Down Expand Up @@ -230,10 +231,6 @@ class Tonic extends window.HTMLElement {
}

_set (target, render, content = '') {
const rootNode = target.getRootNode()
if (rootNode !== document && rootNode.toString() !== '[object ShadowRoot]') {
return
}
for (const node of target.querySelectorAll(Tonic._tags)) {
if (!node.isTonicComponent) continue

Expand Down Expand Up @@ -344,20 +341,25 @@ class Tonic extends window.HTMLElement {

this.willConnect && this.willConnect()

if (!this.isInDocument(this.root)) return
if (!this.preventRenderOnReconnect) {
if (!this._source) {
this._source = this.innerHTML
} else {
this.innerHTML = this._source
}

const p = this._set(this.shadowRoot || this, this.render)
const p = this._set(this.root, this.render)
if (p && p.then) return p.then(() => this.connected && this.connected())
}

this.connected && this.connected()
}

isInDocument (target) {
const root = target.getRootNode()
return root === document || root.toString() === '[object ShadowRoot]'
}

disconnectedCallback () {
this.disconnected && this.disconnected()
delete Tonic._data[this._id]
Expand Down

0 comments on commit 7dd337e

Please sign in to comment.