From 32af027fe41d3e2b343dd13c84b6fbd715a59fae Mon Sep 17 00:00:00 2001 From: Ruben Carvalho Date: Thu, 19 Sep 2024 00:31:06 +0100 Subject: [PATCH] chore: add isUpdating flag to prevent multiple re-renders --- packages/overlay/src/OverlayTrigger.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/overlay/src/OverlayTrigger.ts b/packages/overlay/src/OverlayTrigger.ts index 2e7572d88b..bf296d1ba3 100644 --- a/packages/overlay/src/OverlayTrigger.ts +++ b/packages/overlay/src/OverlayTrigger.ts @@ -110,9 +110,17 @@ export class OverlayTrigger extends SpectrumElement { this.targetContent = this.getAssignedElementsFromSlot(event.target); } + private isUpdatingSlotContent = false; + private handleSlotContent( event: Event & { target: HTMLSlotElement } ): void { + if (this.isUpdatingSlotContent) { + return; + } + + this.isUpdatingSlotContent = true; + switch (event.target.name) { case 'click-content': this.clickContent = this.getAssignedElementsFromSlot( @@ -130,6 +138,8 @@ export class OverlayTrigger extends SpectrumElement { ); break; } + + this.isUpdatingSlotContent = false; } private handleBeforetoggle(event: BeforetoggleOpenEvent): void {