From aab4d306f80851bfd8a02a6361e26d60faeaadb4 Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Fri, 4 Feb 2022 11:39:21 -0500 Subject: [PATCH] fix(datetime): disable intersection observer during month update (#24713) Resolves #24712 --- core/src/components/datetime/datetime.tsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/core/src/components/datetime/datetime.tsx b/core/src/components/datetime/datetime.tsx index 0ddfbe3eb4..42ed82a73b 100644 --- a/core/src/components/datetime/datetime.tsx +++ b/core/src/components/datetime/datetime.tsx @@ -771,17 +771,26 @@ export class Datetime implements ComponentInterface { */ writeTask(() => { - this.setWorkingParts({ - ...this.workingParts, - month, - day: day!, - year - }); + // Disconnect all active intersection observers + // to avoid a re-render causing a duplicate event. + if (this.destroyCalendarIO) { + this.destroyCalendarIO(); + } raf(() => { + this.setWorkingParts({ + ...this.workingParts, + month, + day: day!, + year + }); + calendarBodyRef.scrollLeft = workingMonth.clientWidth * (isRTL(this.el) ? -1 : 1); calendarBodyRef.style.removeProperty('overflow'); calendarBodyRef.style.removeProperty('pointer-events'); + + endIO?.observe(endMonth); + startIO?.observe(startMonth); }); /**