Skip to content

Commit 28447b1

Browse files
committed
Add guard
1 parent e664b06 commit 28447b1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/mixins/view-transition-mixin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const ViewTransitionMixin = <
1010
abstract class ViewTransitionClass extends superClass {
1111
private _slot?: HTMLSlotElement;
1212

13+
private _transitionTriggered = false;
14+
1315
/**
1416
* Trigger a view transition if supported by the browser
1517
* @param updateCallback - Callback function that updates the DOM
@@ -47,9 +49,15 @@ export const ViewTransitionMixin = <
4749
* Check if slot has content and trigger transition if it does
4850
*/
4951
private _checkSlotContent = (): void => {
52+
// Guard against multiple slotchange events triggering the transition multiple times
53+
if (this._transitionTriggered) {
54+
return;
55+
}
56+
5057
if (this._slot) {
5158
const elements = this._slot.assignedElements();
5259
if (elements.length > 0) {
60+
this._transitionTriggered = true;
5361
this.onLoadTransition?.();
5462
}
5563
}

0 commit comments

Comments
 (0)