Skip to content

Commit

Permalink
Fix exception in gap-utils (#6454)
Browse files Browse the repository at this point in the history
**Problem:**
After #6410 , it is
possible that specialSizeMeasurements.gridCellGlobalFrames is outdated,
and if the number of rows/columns changed, it can even have the wrong
number of rows/columns compared to information in other parts of the
metadata.

**Fix:**
Change gridGapControlBoundsFromMetadata in a way that it is resilient to
these problems. The metadata will be eventually fixed when the grid
controls are on (and the gap controls are only visible in that case).

**Manual Tests:**
I hereby swear that:

- [x] I opened a hydrogen project and it loaded
- [x] I could navigate to various routes in Play mode
  • Loading branch information
gbalint authored Oct 2, 2024
1 parent a160566 commit feedd6c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions editor/src/components/canvas/gap-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ export function gridGapControlBoundsFromMetadata(
x: gridCellBounds[0][0].x - parentGridBounds.x,
y: gridCellBounds[0][0].y - parentGridBounds.y,
width:
gridCellBounds[0][gridColumns - 1].x +
gridCellBounds[0][gridColumns - 1].width -
gridCellBounds[0][gridCellBounds[0].length - 1].x +
gridCellBounds[0][gridCellBounds[0].length - 1].width -
gridCellBounds[0][0].x,
height:
gridCellBounds[gridRows - 1][0].y +
gridCellBounds[gridRows - 1][0].height -
gridCellBounds[gridCellBounds.length - 1][0].y +
gridCellBounds[gridCellBounds.length - 1][0].height -
gridCellBounds[0][0].y,
})

// row gaps array
const rowGaps = createArrayWithLength(gridRows - 1, (i) => {
const rowGaps = createArrayWithLength(gridCellBounds.length - 1, (i) => {
// cell i represents the gap between child [i * gridColumns] and child [(i+1) * gridColumns]
const firstChildBounds = gridCellBounds[i][0]
const secondChildBounds = gridCellBounds[i + 1][0]
Expand All @@ -257,7 +257,7 @@ export function gridGapControlBoundsFromMetadata(
})

// column gaps array
const columnGaps = createArrayWithLength(gridColumns - 1, (i) => {
const columnGaps = createArrayWithLength(gridCellBounds[0].length - 1, (i) => {
// cell i represents the gap between child [i] and child [i + 1]
const firstChildBounds = gridCellBounds[0][i]
const secondChildBounds = gridCellBounds[0][i + 1]
Expand Down

0 comments on commit feedd6c

Please sign in to comment.