Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule reflows with requestAnimationFrame #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Saoma1
Copy link

@Saoma1 Saoma1 commented May 16, 2023

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.

@guillaumebriday guillaumebriday self-requested a review May 19, 2023 12:31
@guillaumebriday guillaumebriday added the enhancement New feature or request label May 19, 2023
@guillaumebriday
Copy link
Member

That is a great idea! But on my side it does not fix the problem on Firefox and Chrome...

As mentioned here maybe we should just wrap https://github.com/jackmoore/autosize?

Copy link

@yshmarov yshmarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Saoma1 interesting take! 🤩

Just tried it:

For me, this way it does not jump if the top of the textarea is visible on screen, but otherwise it jumps like crazy:

jumpingbad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants