viewport visibility: use 'key' instead of 'value' for device type #77410
Conversation
…device type across multiple components
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +1 B (0%) Total Size: 7.75 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in c1cbe15. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24495434899
|


What?
Fixes an invalid fallback when reading the editor preview device type from block editor settings.
BLOCK_VISIBILITY_VIEWPORTSonly defineskey,label, andicon— there is novalueproperty. Code that usedBLOCK_VISIBILITY_VIEWPORTS.desktop.valuetherefore always fell through toundefined, so expressions like:getSettings()?.[ deviceTypeKey ]?.toLowerCase() || BLOCK_VISIBILITY_VIEWPORTS.desktop.valuecould resolve to
undefinedwhenever the device type was not yet present in settings. Downstream visibility logic then behaved as if the preview were desktop, which could hide the block visibility inspector notice and cause inconsistent UI (including flaky or failing E2E around the “Block is hidden on Mobile” badge).Why?
BLOCK_VISIBILITY_VIEWPORTS(desktop.key→'desktop').undefined.How?
Replace
BLOCK_VISIBILITY_VIEWPORTS.desktop.valuewithBLOCK_VISIBILITY_VIEWPORTS.desktop.keyin:packages/block-editor/src/components/block-visibility/viewport-visibility-info.jspackages/block-editor/src/hooks/grid-visualizer.jspackages/block-editor/src/hooks/layout-child.jsTesting
Manual
Smoke test the block inspector block visibility label:
hide a block on mobile only, keep it selected, switch the editor View preview between Desktop and Mobile, and confirm the settings sidebar still shows the block-hidden-at-viewport notice when the block is hidden at the current preview.
Smoke test grid:
on a post, add a grid layout, hide the grid or a parent on Mobile only, select the grid container, toggle View between Desktop and Mobile, and confirm the grid visualizer overlay appears when the grid is visible at that preview and stays hidden when it is hidden at that preview.
Automated
npm run test:unit -- packages/block-editor/src/components/block-visibility/test/use-block-visibility.jsnpm run test:e2e -- test/e2e/specs/editor/various/block-hiding.spec.jsKapture.2026-04-16.at.16.21.12.mp4