Skip to content

Commit

Permalink
fix: release dummy wheel listener on workspace dispose (#7693)
Browse files Browse the repository at this point in the history
fix #7674
  • Loading branch information
ananta authored Dec 5, 2023
1 parent 2b00cd8 commit 0836a1d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion core/workspace_svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
}

/**
Expand Down

0 comments on commit 0836a1d

Please sign in to comment.