From 2f65ccd114ce8bcfa1dcc5707dda8697910e08e8 Mon Sep 17 00:00:00 2001 From: Emily KL <4672118+emilykl@users.noreply.github.com> Date: Fri, 8 Aug 2025 15:53:09 -0400 Subject: [PATCH 1/2] fix wheel event handler Violation in Chromium by setting passive: true --- src/lib/events.js | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/lib/events.js b/src/lib/events.js index 6202ece21ef..3b1d990bd92 100644 --- a/src/lib/events.js +++ b/src/lib/events.js @@ -59,15 +59,9 @@ var Events = { internalEv.emit(event, data); }; - /* - * Add a dummy event handler for 'wheel' event for Safari - * to enable mouse wheel zoom. - * https://github.com/d3/d3/issues/3035 - * https://github.com/plotly/plotly.js/issues/7452 - */ - if(typeof plotObj.addEventListener === 'function') { - plotObj.addEventListener("wheel", () => {}); - } + // Add a dummy event handler for 'wheel' event for Safari + // to enable mouse wheel zoom. + addDummyScrollEventListener(plotObj); return plotObj; }, @@ -140,4 +134,35 @@ var Events = { }; +function addDummyScrollEventListener(plotObj) { + /* + * Add a dummy event handler for 'wheel' event for Safari + * to enable mouse wheel zoom. + * https://github.com/d3/d3/issues/3035 + * https://github.com/plotly/plotly.js/issues/7452 + * + * We set {passive: true} for better performance + * and to avoid a Violation warning in Chromium. + * https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md + * https://github.com/plotly/plotly.js/issues/7516 + */ + + // Test whether the passive property is accessed (for compatibility with older browsers) + var supportsPassive = false; + try { + var opts = Object.defineProperty({}, 'passive', { + get: function() { + supportsPassive = true; + } + }); + window.addEventListener("testPassive", null, opts); + window.removeEventListener("testPassive", null, opts); + } catch (e) {} + + if(typeof plotObj.addEventListener === 'function') { + plotObj.addEventListener("wheel", () => {}, supportsPassive ? { passive: true } : false); + } + +} + module.exports = Events; From 4054a618d998a9781832b69d7b7a081f48eb64a6 Mon Sep 17 00:00:00 2001 From: Emily KL <4672118+emilykl@users.noreply.github.com> Date: Mon, 11 Aug 2025 11:37:43 -0400 Subject: [PATCH 2/2] simplify by removing handling for very old browsers --- src/lib/events.js | 48 ++++++++++++++--------------------------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/src/lib/events.js b/src/lib/events.js index 3b1d990bd92..725ff59791d 100644 --- a/src/lib/events.js +++ b/src/lib/events.js @@ -59,9 +59,20 @@ var Events = { internalEv.emit(event, data); }; - // Add a dummy event handler for 'wheel' event for Safari - // to enable mouse wheel zoom. - addDummyScrollEventListener(plotObj); + /* + * Add a dummy event handler for 'wheel' event for Safari + * to enable mouse wheel zoom. + * https://github.com/d3/d3/issues/3035 + * https://github.com/plotly/plotly.js/issues/7452 + * + * We set {passive: true} for better performance + * and to avoid a Violation warning in Chromium. + * https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md + * https://github.com/plotly/plotly.js/issues/7516 + */ + if(typeof plotObj.addEventListener === 'function') { + plotObj.addEventListener("wheel", () => {}, { passive: true }); + } return plotObj; }, @@ -134,35 +145,4 @@ var Events = { }; -function addDummyScrollEventListener(plotObj) { - /* - * Add a dummy event handler for 'wheel' event for Safari - * to enable mouse wheel zoom. - * https://github.com/d3/d3/issues/3035 - * https://github.com/plotly/plotly.js/issues/7452 - * - * We set {passive: true} for better performance - * and to avoid a Violation warning in Chromium. - * https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md - * https://github.com/plotly/plotly.js/issues/7516 - */ - - // Test whether the passive property is accessed (for compatibility with older browsers) - var supportsPassive = false; - try { - var opts = Object.defineProperty({}, 'passive', { - get: function() { - supportsPassive = true; - } - }); - window.addEventListener("testPassive", null, opts); - window.removeEventListener("testPassive", null, opts); - } catch (e) {} - - if(typeof plotObj.addEventListener === 'function') { - plotObj.addEventListener("wheel", () => {}, supportsPassive ? { passive: true } : false); - } - -} - module.exports = Events;