Skip to content

Commit

Permalink
keep mount/unmount calls always symmetric
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Voytenko committed Mar 17, 2021
1 parent 08e103e commit 444d718
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ function createBaseCustomElementClass(win, elementConnectedCallback) {
/** @private {?Promise} */
this.buildingPromise_ = null;

/**
* Indicates that the `mountCallback()` has been called and it hasn't
* been reversed with an `unmountCallback()` call.
* @private {boolean}
*/
this.mounted_ = false;

/** @private {?Promise} */
this.mountPromise_ = null;

Expand Down Expand Up @@ -625,6 +632,7 @@ function createBaseCustomElementClass(win, elementConnectedCallback) {
? ReadyState.LOADING
: ReadyState.MOUNTING
);
this.mounted_ = true;
return this.impl_.mountCallback(signal);
})
.then(() => {
Expand Down Expand Up @@ -715,11 +723,12 @@ function createBaseCustomElementClass(win, elementConnectedCallback) {
scheduler.unschedule(this);

// Try to unmount if the element has been built already.
if (this.isBuilt()) {
if (this.mounted_) {
this.impl_.unmountCallback();
}

// Complete unmount and reset the state.
this.mounted_ = false;
this.mountPromise_ = null;
this.signals_.reset(CommonSignals.MOUNTED);

Expand Down

0 comments on commit 444d718

Please sign in to comment.