fix: prevent resize observer feedback loop in vertical mode#875
Merged
Conversation
When using vertical direction with certain CSS layouts, the ResizeObserver could fire repeatedly with sub-pixel size variations, causing an infinite re-render loop. Changes: - Round container size to nearest integer before processing - Track last observed size via ref to skip redundant updates - Add tests verifying stability with sub-pixel variations - Confirm significant size changes still trigger proper updates Fixes #873
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Root Cause
When using
direction="vertical"with certain container sizing setups (like CSS solution #3 from the docs), the ResizeObserver would fire repeatedly with tiny sub-pixel variations (768.0, 768.1, 768.2, etc.). Each update would trigger a state change, which affected layout, which triggered another ResizeObserver callback, creating an infinite loop.Solution
Round the observed size to the nearest integer before comparison and state updates. This prevents sub-pixel "noise" from causing updates while still responding to meaningful 1+ pixel size changes.
Test Plan
Fixes #873