Skip to content

Commit 79c9425

Browse files
committed
Don’t set _updateComplete in _enqueueUpdate, but return the new Promise to be set.
1 parent bb78d41 commit 79c9425

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

src/lib/updating-element.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ export abstract class UpdatingElement extends HTMLElement {
603603
}
604604
}
605605
if (!this._hasRequestedUpdate && shouldRequestUpdate) {
606-
this._enqueueUpdate();
606+
this._updatePromise = this._enqueueUpdate();
607607
}
608608
}
609609

@@ -628,26 +628,24 @@ export abstract class UpdatingElement extends HTMLElement {
628628
/**
629629
* Sets up the element to asynchronously update.
630630
*/
631-
private _enqueueUpdate() {
631+
private async _enqueueUpdate() {
632632
this._updateState = this._updateState | STATE_UPDATE_REQUESTED;
633-
this._updatePromise = (async () => {
634-
try {
635-
// Ensure any previous update has resolved before updating.
636-
// This `await` also ensures that property changes are batched.
637-
await this._updatePromise;
638-
} catch (e) {
639-
// Ignore any previous errors. We only care that the previous cycle is
640-
// done. Any error should have been handled in the previous update.
641-
}
642-
const result = this.performUpdate();
643-
// If `performUpdate` returns a Promise, we await it. This is done to
644-
// enable coordinating updates with a scheduler. Note, the result is
645-
// checked to avoid delaying an additional microtask unless we need to.
646-
if (result != null) {
647-
await result;
648-
}
649-
return !this._hasRequestedUpdate;
650-
})();
633+
try {
634+
// Ensure any previous update has resolved before updating.
635+
// This `await` also ensures that property changes are batched.
636+
await this._updatePromise;
637+
} catch (e) {
638+
// Ignore any previous errors. We only care that the previous cycle is
639+
// done. Any error should have been handled in the previous update.
640+
}
641+
const result = this.performUpdate();
642+
// If `performUpdate` returns a Promise, we await it. This is done to
643+
// enable coordinating updates with a scheduler. Note, the result is
644+
// checked to avoid delaying an additional microtask unless we need to.
645+
if (result != null) {
646+
await result;
647+
}
648+
return !this._hasRequestedUpdate;
651649
}
652650

653651
private get _hasRequestedUpdate() {

0 commit comments

Comments
 (0)