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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bug Fix

- Listen to `resize` events correctly in `useBreakpointIndex`. This hook is used in `useResponsiveValue` and consequently in the `Flex` and `Grid` components ([#33902](https://github.com/WordPress/gutenberg/pull/33902))

## 15.0.0 (2021-07-29)

### Breaking Change
Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/ui/utils/use-responsive-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export const useBreakpointIndex = (

onResize();

if ( typeof document !== 'undefined' ) {
if ( typeof window !== 'undefined' ) {
// Disable reason: We don't really care about what document we listen to, we just want to know that we're resizing.
/* eslint-disable @wordpress/no-global-event-listener */
document.addEventListener( 'resize', onResize );
window.addEventListener( 'resize', onResize );
}
return () => {
if ( typeof document !== 'undefined' ) {
document.removeEventListener( 'resize', onResize );
if ( typeof window !== 'undefined' ) {
window.removeEventListener( 'resize', onResize );
/* eslint-enable @wordpress/no-global-event-listener */
}
};
Expand Down