Skip to content

[Issue] Avoid binding magnifier events in duplicate on resize #30788

Closed
@m2-assistant

Description

@m2-assistant

This issue is automatically created based on existing pull request: #30695: Avoid binding magnifier events in duplicate on resize


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

  1. Visit a product page with magnifier in use and configured for hover events
  2. Observe the resting CPU usage of the page
  3. Resize the viewport (either height or width)
  4. Observe a spike in CPU usage, which subsides
  5. Resize the viewport several times
  6. Observe a progressively longer spike in CPU usage
  7. Continue resizing the viewport and notice that CPU eventually (after ~8 resizes in my experience) caps out at 100% for an unacceptable amount of time (several minutes), rendering the page useless.
Before & after pictures from JavaScript profiler

Before:
Screenshot_2020-10-28_15-46-27

After:
Screenshot_2020-10-28_16-38-10

Questions or comments

None

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: ImageFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Priority: P3May be fixed according to the position in the backlog.Progress: doneReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions