-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Avoid binding magnifier events in duplicate on resize #30695
Avoid binding magnifier events in duplicate on resize #30695
Conversation
This is particularly important as a resize event will trigger a call to this (via resize -> _init() -> set() -> image load -> image load -> bindEvents()) and the 'hover' event type also triggers a 'mouseover' event having added an event listener for the same. This all means that each time a browser sends a resize event (which can happen on other events than a viewport width/height change) more event listeners are stacked, leading to significant CPU usage for no value.
Hi @fredden. Thank you for your contribution
❗ Automated tests can be triggered manually with an appropriate comment:
You can find more information about the builds here ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review. For more details, please, review the Magento Contributor Guide documentation. 🕙 You can find the schedule on the Magento Community Calendar page. 📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket. 🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel ✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel |
@magento run Functional Tests EE, Functional Tests CE |
@fredden good catch! Looks like it will be too hard to cover with automated test, so I put label "auto-tests: not required" |
@magento run Functional Tests B2B |
@magento run all tests |
✔️ QA passed Was checked case from Manual testing scenarios
|
Hi @fredden, thank you for your contribution! |
Description
A browser resize event will trigger the magnifier to be re-initialised. This includes binding a fresh set of event listeners to the image so that the magnifier will show as expected (on click or hover). However, there is no mechanism to unbind the old event listeners, so each time the browser triggers a resize event these will stack.
This is made worse by the 'hover' event type triggering the 'mouseover' event immediately after adding a listener for the same. This means that each resize event will consume progressively more CPU, without any additional value.
Related Pull Requests
None
Fixed Issues
None
Manual testing scenarios
Before & after pictures from JavaScript profiler
Before:
After:
Questions or comments
None
Contribution checklist
Resolved issues: