Prevent utils.synchronizeLayoutWithChildren() from forcing components to collide #342
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey Samuel,
We just deployed RGL to production at Reflect, and wanted to thank you for your work. 👏 Shortly after deploying we found a pretty bad bug that I wanted to surface to you.
We've been running into a problem where sometimes, the grid that is rendered is
different than the grid we specify through
layout
. We found this could befixed by reversing the order in which we pass our children grid items to RGL,
which led us to believe there was a bug in RGL that was modifying
y
.After some debugging, we found
utils.synchronizeLayoutWithChildren()
to be the culprit.
As an example, here's the layout we were providing:
When rendered, the first item should visually be below the second. However,
since
synchronizeLayoutWithChildren
synchronizes the layout in the orderit is provided, it was updating the
y
property of the first itemto be
Math.min(bottom(layout), g.y),
, which would end up equaling 0.This meant that (when
static
wasfalse
), RGL would eventually recognizethe new collision and update the second item to be visually below the first,
by setting its
y
value to 2.This was resulting in the grid looking like this:
My proposed change moves this logic down into the
utils.compactItem()
function, since the layout has been sorted by the time this function is
called. Because we're now iterating through the items after they've been
sorted, this is no longer a problem and the correct grid is rendered.