GridVisualizer: Avoid over-selecting by using a new getBlockStyles private selector#64386
Conversation
|
Size Change: +173 B (+0.01%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
1e19e46 to
7b52f34
Compare
|
Flaky tests detected in 7b52f34. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10347138155
|
7b52f34 to
24aa991
Compare
|
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. |
talldan
left a comment
There was a problem hiding this comment.
Testing well for me, and the code looks very tidy. Nice work!
| const occupiedRects = useMemo( () => { | ||
| const rects = []; | ||
| for ( const block of gridItems ) { | ||
| for ( const style of Object.values( gridItemStyles ) ) { |
There was a problem hiding this comment.
I noticed that it means occupiedRects may no longer be in block order (as it's sourced from an object).
I think it's ok though, the only thing I can see it's used for is this code, which doesn't depend on the ordering:
const isCellOccupied = occupiedRects.some( ( rect ) =>
rect.contains( column, row )
);There was a problem hiding this comment.
Yeah order isn't important.
See #63976.
Stacked onto #64321.GridPopoverwas callinggetBlocks( gridClientId )which returns a new array reference every time any inner block in the grid changes. This causes all ofGridVisualizerto update when typing into a grid cell.We only care about when one of the attributes in
style.layoutchanges, so I've fixed this by adding a new private selector that returns only thestylekey of the given blocks.Before:
before.mp4
After:
after.mp4