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

useBreakpointIndex: attach resize event listener to window instead of document #33902

Merged
merged 2 commits into from
Aug 6, 2021

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Aug 5, 2021

Description

Fix a bug in the useBreakpointIndex component utility hook, where the resize event listener was previously attached to the document object.

This was resulting in the event listener function never being called, since the resize event only gets fired on the window object.

The fix is quite simple — change document to window.

How has this been tested?

One way to test this is to check the Flex component's Storybook example:

  • in production, notice how resizing the window doesn't cause the second row of items to switch from row to column (and viceversa)
  • When running Storybook on this PR branch, notice how the behaviour just described above is fixed

Screenshots

Before

flex-breakpoint-before.mp4

After

flex-breakpoint-after.mp4

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • N/A I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@ciampo ciampo added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components [Feature] Component System WordPress component system labels Aug 5, 2021
@ciampo ciampo self-assigned this Aug 5, 2021
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

TIL! Thanks for the fix.

FWIW I still think this "feature" should be carefully evaluated, whether it's actually a good one to include now or something we can just add in the future.

Of course it's usages are already in non-experimental components (like Flex) so it might be too late to do so.

@ciampo
Copy link
Contributor Author

ciampo commented Aug 5, 2021

TIL! Thanks for the fix.

FWIW I still think this "feature" should be carefully evaluated, whether it's actually a good one to include now or something we can just add in the future.

Of course it's usages are already in non-experimental components (like Flex) so it might be too late to do so.

I agree with you — I'm also not a fan of this pattern where an array of values are applied given a responsive configuration. It just feels a bit of an unnecessary construct around what could be easily implemented via CSS (or a separate utility from each component anyway).

It seems that the only components using this pattern are Flex (for the direction prop) and Grid (row and column props)

@ciampo ciampo force-pushed the fix/use-breakpoint-index-resize-event-listener-target branch from 04e6ce5 to 5f12042 Compare August 5, 2021 16:15
@ciampo ciampo merged commit ac9ab86 into trunk Aug 6, 2021
@ciampo ciampo deleted the fix/use-breakpoint-index-resize-event-listener-target branch August 6, 2021 09:20
@github-actions github-actions bot added this to the Gutenberg 11.3 milestone Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Component System WordPress component system [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants