Skip to content
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
1 change: 1 addition & 0 deletions packages/compose/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bug Fixes

- `useFixedWindowList`: Remove a duplicate `resize` listener registration, and page by the measured viewport height rather than the initial window size ([#80935](https://github.com/WordPress/gutenberg/pull/80935)).
- `useViewportMatch`: Scope the generated media query to `screen`, so that printing does not report the viewport as having become narrower ([#81367](https://github.com/WordPress/gutenberg/pull/81367)).

## 8.5.0 (2026-07-29)

Expand Down
4 changes: 3 additions & 1 deletion packages/compose/src/hooks/use-viewport-match/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ const useViewportMatch = (
: undefined
): boolean => {
const simulatedWidth = useContext( ViewportMatchWidthContext );
// Scoped to `screen` so printing, which matches against the page box,
// does not read as a narrower viewport.
const mediaQuery =
! simulatedWidth &&
`(${ CONDITIONS[ operator ] }: ${ BREAKPOINTS[ breakpoint ] }px)`;
`screen and (${ CONDITIONS[ operator ] }: ${ BREAKPOINTS[ breakpoint ] }px)`;
const mediaQueryResult = useMediaQuery( mediaQuery || undefined, view );

if ( simulatedWidth ) {
Expand Down
12 changes: 6 additions & 6 deletions packages/compose/src/hooks/use-viewport-match/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ describe( 'useViewportMatch', () => {
expect( useMediaQueryMock ).toHaveBeenCalledTimes( 3 );
expect( useMediaQueryMock ).toHaveBeenNthCalledWith(
1,
'(max-width: 1280px)',
'screen and (max-width: 1280px)',
Comment thread
ramonjd marked this conversation as resolved.
window
);
expect( useMediaQueryMock ).toHaveBeenNthCalledWith(
2,
'(min-width: 782px)',
'screen and (min-width: 782px)',
window
);
expect( useMediaQueryMock ).toHaveBeenNthCalledWith(
3,
'(min-width: 600px)',
'screen and (min-width: 600px)',
window
);
} );
Expand All @@ -70,17 +70,17 @@ describe( 'useViewportMatch', () => {
expect( useMediaQueryMock ).toHaveBeenCalledTimes( 3 );
expect( useMediaQueryMock ).toHaveBeenNthCalledWith(
1,
'(min-width: 1440px)',
'screen and (min-width: 1440px)',
window
);
expect( useMediaQueryMock ).toHaveBeenNthCalledWith(
2,
'(max-width: 960px)',
'screen and (max-width: 960px)',
window
);
expect( useMediaQueryMock ).toHaveBeenNthCalledWith(
3,
'(max-width: 480px)',
'screen and (max-width: 480px)',
window
);
} );
Expand Down
3 changes: 3 additions & 0 deletions packages/viewport/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

### Bug Fixes

- Scope the breakpoint media queries to `screen`, so that printing does not report the viewport as having become narrower ([#81367](https://github.com/WordPress/gutenberg/pull/81367)).

## 6.52.0 (2026-07-29)

Expand Down
4 changes: 3 additions & 1 deletion packages/viewport/src/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ const addDimensionsEventListener = (
( [ name, width ] ) => {
return operatorEntries.map(
( [ operator, condition ] ): [ string, MediaQueryList ] => {
// Scoped to `screen` so printing, which matches against
// the page box, does not read as a narrower viewport.
const list = window.matchMedia(
`(${ condition }: ${ width }px)`
`screen and (${ condition }: ${ width }px)`
);
list.addEventListener( 'change', setIsMatching );
return [ `${ operator } ${ name }`, list ];
Expand Down
Loading