Skip to content

Grid overlays: Use canvas iframe window for viewport visibility detection#79255

Open
t-hamano wants to merge 4 commits into
trunkfrom
fix/grid-overlay-viewport-canvas-view
Open

Grid overlays: Use canvas iframe window for viewport visibility detection#79255
t-hamano wants to merge 4 commits into
trunkfrom
fix/grid-overlay-viewport-canvas-view

Conversation

@t-hamano

@t-hamano t-hamano commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Related to #76889
Follow up to #74963, #75078

Discovered this while working on #75121

What?

The grid editing overlay determines if a block is hidden in the current viewport solely using the deviceType state. Consequently, if the browser width is manually resized, grid cells and resize handles remain unintentionally, even if the block is hidden in that viewport. This PR resolves that issue by passing the block's canvas iframe window to useBlockVisibility in both overlays. This approach is already implemented in the block visibility badge.

Testing Instructions

  1. Insert a Grid block with child blocks.
  2. Select the Grid block → block settings (⋮) menu → Visibility → set hidden on Tablet.
  3. Keep the device preview on Desktop.
  4. Select a grid child block so the grid line overlay appears.
  5. As the browser width changes, the block should disappear at the same time as the grid editing UI.
  6. Enable grid interactivity and test again.

Screenshots

Before

before.mp4

After

after.mp4

Use of AI Tools

This PR was authored with the assistance of Claude (Claude Code). The investigation, code changes, and description were generated with AI and reviewed by the contributor.

…tion

Pass the block's canvas iframe window to useBlockVisibility in the grid
visualizer and grid child overlays so viewport detection matches the
actual block rendering context. Previously these overlays relied only on
the deviceType override and read the main editor window, so the grid
visualizer and resize handles could disagree with the block's actual
hidden state when the canvas was resized (device preview or manual drag).

This aligns both overlays with the block.js / use-block-props pattern of
passing both deviceType and view.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

Size Change: +91 B (0%)

Total Size: 8.6 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 380 kB +91 B (+0.02%)

compressed-size-action

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Layout Layout block support, its UI controls, and style output. labels Jun 17, 2026
@t-hamano t-hamano marked this pull request as ready for review June 17, 2026 03:51
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano self-assigned this Jun 17, 2026
@github-actions

Copy link
Copy Markdown

Flaky tests detected in 87cffb4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27663952497
📝 Reported issues:

@tellthemachines

Copy link
Copy Markdown
Contributor

The grid editing overlay determines if a block is hidden in the current viewport solely using the deviceType state

Not for the block itself, because useBlockVisibility calls useViewportMatch to check the viewport size, but I think what's happening is the sidebars are interfering. On trunk, the grid visualizer stays hidden if no sidebars are open:

visibility_grid.mp4

So that's why passing "view" to useBlockVisibility fixes it!

In testing this I noticed that if the selected block is in a Grid whose ancestor is hidden, the visualizer still shows 😅

Screenshot 2026-06-18 at 11 59 48 am

t-hamano and others added 3 commits June 19, 2026 18:21
When a child block inside a grid is selected, layout-child.js renders the
grid visualizer for the parent grid. It only checked the parent grid's own
viewport visibility, not whether any ancestor of the grid was hidden, so the
visualizer kept showing for grids nested under a hidden ancestor.

Mirror the ancestor check already used in grid-visualizer.js via
isBlockParentHiddenAtViewport so the visualizer is hidden in that case too.

Co-Authored-By: Claude <noreply@anthropic.com>
The ancestor-hidden check used the device type, but blocks are hidden based
on the viewport actually detected from the canvas iframe. In Desktop mode
with a narrow canvas the two diverge, so the visualizer/resize handles kept
showing for a grid (or its child) nested under an ancestor hidden at the
real viewport.

Move the isAnyAncestorHidden check into a selector keyed on the canvas
currentViewport from useBlockVisibility, so it stays consistent with how
blocks are actually hidden. Applies to both the grid-selected and
child-selected paths.

Co-Authored-By: Claude <noreply@anthropic.com>
@t-hamano

Copy link
Copy Markdown
Contributor Author

Okay, I think I've fixed all the issues.

In testing this I noticed that if the selected block is in a Grid whose ancestor is hidden, the visualizer still shows 😅

This was due to a missing check for ancestor blocks. 49ad162 should fix it.

Another thing I noticed is that the ancestor block check was based on deviceType, which meant the grid visualizer didn't change when manually resizing the browser width. This issue was resolved by using the currentViewport returned from the useBlockVisibility hook, similar to the ViewportVisibilityInfo component.

block-visibility.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Layout Layout block support, its UI controls, and style output. [Package] Block editor /packages/block-editor [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