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).
Copy link
Contributor

@sarayourfriend sarayourfriend left a comment

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 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 Aug 5, 2021
@ciampo ciampo merged commit ac9ab86 into trunk Aug 6, 2021
19 checks passed
19 checks passed
@github-actions
Compute current and next stable release branches
Details
@github-actions
test
Details
@github-actions
Checks (12)
Details
@github-actions
Admin - 1 Admin - 1
Details
@github-actions
Run performance tests
Details
@github-actions
pull-request-automation (14)
Details
@github-actions
test (12.2, gutenberg-editor-initial-html, 14)
Details
@github-actions
JavaScript (12)
Details
@github-actions
Checks (14)
Details
@github-actions
Admin - 2 Admin - 2
Details
@github-actions
JavaScript (14)
Details
@github-actions
Admin - 3 Admin - 3
Details
@github-actions
Admin - 4 Admin - 4
Details
@github-actions
Bump version
Details
@github-actions
Build Release Artifact
Details
@github-actions
Mobile
Details
@github-actions
Create Release Draft and Attach Asset
Details
@ciampo ciampo deleted the fix/use-breakpoint-index-resize-event-listener-target branch Aug 6, 2021
@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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants