Schedule reflows with requestAnimationFrame #9
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.
Description:
The current behavior of the textarea autogrow causes scrolling problems, the scrollbar may jump or scroll unexpectedly, see video below. I believe the bug arises from the reflow caused by the autogrow functionality of the textarea, more info can be found here. Additionally, the proposed solution also resolves the issue from @yshmarov, #3.
autogrow.scroll.bug.mov
Solution:
The fix introduced in this pull request utilizes the
requestAnimationFrame
method to optimize the textarea autogrow behavior. When the textarea's height needs to be adjusted, instead of making immediate changes, we schedule the adjustment to occur during the next animation frame. This ensures that the browser can handle the layout changes more efficiently and prevents the scroll issues that occurred during reflow. By synchronizing the height adjustment with the browser's rendering cycle, we achieve a smoother and more stable scrolling experience.Please review this pull request and provide any feedback or suggestions.