From 0836a1db10e1587bd60e849e446eb2a8bced0e21 Mon Sep 17 00:00:00 2001 From: Ananta Bastola <12180395+ananta@users.noreply.github.com> Date: Tue, 5 Dec 2023 12:42:35 -0500 Subject: [PATCH] fix: release dummy wheel listener on workspace dispose (#7693) fix #7674 --- core/workspace_svg.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/workspace_svg.ts b/core/workspace_svg.ts index 1cfdbbc37..fe1386587 100644 --- a/core/workspace_svg.ts +++ b/core/workspace_svg.ts @@ -247,6 +247,12 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { | ((menuOptions: ContextMenuOption[], e: Event) => void) | null = null; + /** + * A dummy wheel event listener used as a workaround for a Safari scrolling issue. + * Set in createDom and used for removal in dispose to ensure proper cleanup. + */ + private dummyWheelListener: (() => void) | null = null; + /** * In a flyout, the target workspace where blocks should be placed after a * drag. Otherwise null. @@ -787,7 +793,8 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { // This no-op works around https://bugs.webkit.org/show_bug.cgi?id=226683, // which otherwise prevents zoom/scroll events from being observed in // Safari. Once that bug is fixed it should be removed. - document.body.addEventListener('wheel', function () {}); + this.dummyWheelListener = () => {}; + document.body.addEventListener('wheel', this.dummyWheelListener); browserEvents.conditionalBind( this.svgGroup_, 'wheel', @@ -896,6 +903,12 @@ export class WorkspaceSvg extends Workspace implements IASTNodeLocationSvg { browserEvents.unbind(this.resizeHandlerWrapper); this.resizeHandlerWrapper = null; } + + // Remove the dummy wheel listener + if (this.dummyWheelListener) { + document.body.removeEventListener('wheel', this.dummyWheelListener); + this.dummyWheelListener = null; + } } /**