Skip to content

Commit 92f5515

Browse files
committed
Make wheel listener active
Recently chrome changed the behavior of wheel listeners to be passive by default. Passive listeners cannot cancel event propagation. When a wheel event propagates outside of the canvas it can drastically slow down the browser as the parent elements try to compute whether or not they can scroll. This change uses manual event listener management to add active listeners, which is inline w/ the behavior for chrome before version 73. Test plan: use mousewheel. Notice there are no console.warn messages about passive listeners anymore. Semver impact: this is semver patch. Bugfix only. Further reading: facebook/react#14856 facebook/react#6436
1 parent 7bd8c38 commit 92f5515

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/regl-worldview/src/camera/CameraListener.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ export default class CameraListener extends React.Component<Props> {
6868
};
6969
listen(document, "blur", this._onBlur);
7070
listen(window, "mouseup", this._onWindowMouseUp);
71+
_el.addEventListener("wheel", this._onWheel, { passive: false });
7172
}
7273

7374
componentWillUnmount() {
7475
this._listeners.forEach((listener) => {
7576
listener.target.removeEventListener(listener.name, listener.fn);
7677
});
7778
this._endDragging();
79+
const { _el } = this;
80+
if (!_el) {
81+
return;
82+
}
83+
_el.removeEventListener("wheel", this._onWheel, { passive: false });
7884
}
7985

8086
_getMouseOnScreen = (mouse: MouseEvent) => {
@@ -405,7 +411,6 @@ export default class CameraListener extends React.Component<Props> {
405411
ref={(el) => (this._el = el)}
406412
onMouseDown={this._onMouseDown}
407413
onMouseUp={this._onMouseUp}
408-
onWheel={this._onWheel}
409414
onBlur={this._onBlur}
410415
onContextMenu={this._onContextMenu}
411416
onKeyDown={this._onKeyDown}

0 commit comments

Comments
 (0)