Skip to content
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

Map block: Remove resize event listener when component is unmounted #18489

Merged

Conversation

andrewserong
Copy link
Member

If using the Map block in a custom block preview (for example as part of a pattern in the page layout picker in: Automattic/wp-calypso#49101), when the user switches their pattern selection and the Map block is unmounted, the resize listener continues to fire if the user resizes the window. This results in a TypeError in the console, because the DOM element for the Map component is no longer around:

image

The fix is to add a removeEventListener call when the component is unmounted.

Changes proposed in this Pull Request:

  • In the Map block's main component, add a window.removeEventListener call to remove the resize listener when the component is unmounted.

Jetpack product discussion

Does this pull request change what data or activity we track or use?

No

Testing instructions:

  • For an example where the bug occurred apply [Blocked] Starter page templates: Remove iframe from preview wp-calypso#49101 in a sandbox, and go to add a new page.
  • Select a page layout that includes the Map component (the second last one under the Contact heading).
  • Then, select a different page layout.
  • Resize the window.
  • Without this change applied, you should see an error message similar to the screenshot above
  • With the change applied, particular error should not appear

Test for regressions:

  • Insert the Map block (or a pattern containing it) into a post or page
  • Resize the editor, and the Map block should resize
  • Publish the post or page, and check that resizing the window resizes the Map block

Proposed changelog entry for your changes:

  • Fix bug where Map block resize event listener was not removed when component unmounts

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello andrewserong! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D55824-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@andrewserong andrewserong self-assigned this Jan 22, 2021
@andrewserong andrewserong added [Status] Needs Team Review Obsolete. Use Needs Review instead. [Type] Bug When a feature is broken and / or not performing as intended labels Jan 22, 2021
@andrewserong andrewserong requested a review from a team January 22, 2021 04:22
@jetpackbot
Copy link
Collaborator

Scheduled Jetpack release: February 2, 2021.
Scheduled code freeze: January 25, 2021

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Generated by 🚫 dangerJS against 8a6b073

Copy link
Contributor

@glendaviesnz glendaviesnz left a comment

Choose a reason for hiding this comment

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

LGTM - the map contact page seems to have disappeared from the starter page templates, but you can replicate the issue by adding a map block to a post, deleting it and then resizing window

@glendaviesnz glendaviesnz added [Status] Needs Review This PR is ready for review. and removed [Status] Needs Team Review Obsolete. Use Needs Review instead. labels Jan 27, 2021
@jeherve jeherve added this to the 9.5 milestone Jan 29, 2021
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Jan 29, 2021
@apeatling apeatling merged commit c9a762f into master Jan 29, 2021
@apeatling apeatling deleted the fix/remove-resize-event-listener-when-map-block-unmounts branch January 29, 2021 18:06
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Jan 29, 2021
@andrewserong
Copy link
Member Author

r220776-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Map Touches WP.com Files [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants