Skip to content

Add dummy 'wheel' event handler to enable scroll zoom on safari #7474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 18, 2025

Conversation

emilykl
Copy link
Contributor

@emilykl emilykl commented Jul 17, 2025

Closes #7452

@emilykl emilykl force-pushed the safari-scroll-zoom branch from 68f04da to 06c3e7f Compare July 17, 2025 21:07
@emilykl emilykl force-pushed the safari-scroll-zoom branch from 8370097 to e6618c6 Compare July 17, 2025 22:51
@gvwilson gvwilson added P1 needed for current cycle fix fixes something broken labels Jul 18, 2025
Copy link
Contributor

@archmoj archmoj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update.
Please add a draft log.
💃

Comment on lines +68 to +70
if(typeof plotObj.addEventListener === 'function') {
plotObj.addEventListener("wheel", () => {});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the if block necessary? Can plotObj be undefined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camdecoster There's several tests which pass an empty object ({}) as plotObj, which was leading to an error causing the test to fail.

I'm not sure if plotObj is supposed to be a DOM object or if other types are allowed.

Copy link
Contributor Author

@emilykl emilykl Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like in the actual code (tests aside), Events.init() is only called in one place, and the argument is the output of getGraphDiv(), which cannot be null or undefined but it could theoretically be some other type besides a DOM element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should modify the tests rather than adding this if statement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just use the optional chaining operator? I think that would essentially do the same thing as the if block, but is more compact and you wouldn't have to update any tests.
plotObj?.addEventListener("wheel", () => {});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, TIL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camdecoster I've reverted to the if statement due to the conditional chaining operator not being supported in our build pipeline (see #7477) -- are you OK with me merging as it is currently?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this code will work fine.

@emilykl emilykl marked this pull request as ready for review July 18, 2025 16:22
* https://github.com/d3/d3/issues/3035
* https://github.com/plotly/plotly.js/issues/7452
*/
plotObj.addEventListener?.("wheel", () => {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The operator should come after plotObj in case that value is null/undefined. Where it is now, it could fail if plotObj isn't defined.

Suggested change
plotObj.addEventListener?.("wheel", () => {});
plotObj?.addEventListener("wheel", () => {});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camdecoster Yes, but the specific case causing the test failures was that plotObj was defined but plotObj.addEventListener was undefined.

I guess we could do plotObj?.addEventListener?.("wheel", () => {}); to cover both.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I misunderstood what you were saying before. In this case, plotObj equals {}. Then it's fine to leave it as you had it. No need to add unnecessary checks. It can always be addressed later if it becomes a problem.

@emilykl emilykl force-pushed the safari-scroll-zoom branch from 876c90a to b142a3d Compare July 18, 2025 17:42
Co-authored-by: Mojtaba Samimi <[email protected]>
package.json Outdated
},
"overrides": {
"falafel": {
"acorn": "^8.1.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel comfortable introducing overriding dependencies like that in this PR, specially if we want to release a patch.
IMHO This should be discussed in a separate PR.
I suggest we use bring back the if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I'll put back the if statement for now and open a separate PR for discussing upgrading acorn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@archmoj @camdecoster I have opened #7478 regarding the acorn override

@archmoj
Copy link
Contributor

archmoj commented Jul 18, 2025

Thank you @emilykl
💃

@archmoj archmoj merged commit c9a6b3b into master Jul 18, 2025
6 checks passed
@archmoj archmoj deleted the safari-scroll-zoom branch July 18, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix fixes something broken P1 needed for current cycle
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Scroll zoom doesn't work in safari
4 participants