Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(useTextareaAutosize): improve resize handling with requestAnimationFrame #4557

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

Merged
merged 5 commits into from
Feb 15, 2025

Conversation

ilyaliao
Copy link
Member

@ilyaliao ilyaliao commented Feb 2, 2025

fix: #4556

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.
⚠️ Slowing down new functions

Warning: Slowing down new functions

As the VueUse audience continues to grow, we have been inundated with an overwhelming number of feature requests and pull requests. As a result, maintaining the project has become increasingly challenging and has stretched our capacity to its limits. As such, in the near future, we may need to slow down our acceptance of new features and prioritize the stability and quality of existing functions. Please note that new features for VueUse may not be accepted at this time. If you have any new ideas, we suggest that you first incorporate them into your own codebase, iterate on them to suit your needs, and assess their generalizability. If you strongly believe that your ideas are beneficial to the community, you may submit a pull request along with your use cases, and we would be happy to review and discuss them. Thank you for your understanding.


Description

This PR fixes ResizeObserver loop errors by wrapping resize triggers in requestAnimationFrame.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Feb 2, 2025
textareaOldWidth.value = contentRect.width
triggerResize()

requestAnimationFrame(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need window.requestAnimationFrame()? If yes we also need options.window and can pass it to useResizeObserver 😄

Copy link
Collaborator

Choose a reason for hiding this comment

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

why don't we implement this in the resizeobserver? dont we need this in most cases?

Copy link
Member Author

@ilyaliao ilyaliao Feb 3, 2025

Choose a reason for hiding this comment

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

why don't we implement this in the resizeobserver? dont we need this in most cases?

Are you mean useResizeObserver? Or what are you referring to?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you mean useResizeObserver? Or what are you referring to?

should we wrap every callback from useResizeObserver into requestAnimationFrame to prevent this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@OrbisK OrbisK Feb 3, 2025

Choose a reason for hiding this comment

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

maybe not. should be just a wrapper around ResizeObserver

Copy link
Member Author

@ilyaliao ilyaliao Feb 3, 2025

Choose a reason for hiding this comment

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

I see, this is worth discussing. I guess requestAnimationFrame is not necessary in all cases (e.g: state change).

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Feb 3, 2025
OrbisK
OrbisK previously approved these changes Feb 3, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 3, 2025
antfu
antfu previously approved these changes Feb 12, 2025
textareaOldWidth.value = contentRect.width
triggerResize()

window?.requestAnimationFrame(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should fallback to execute this immediately when window does not exist?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know when this will be needed, but what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

what about tryRequestAnimationFrame 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean ?

function tryRequestAnimationFrame(fn: Fn) {
  if (typeof requestAnimationFrame === 'function') {
    requestAnimationFrame(fn)
  }
  else {
    fn()
  }
}

Copy link
Collaborator

@OrbisK OrbisK Feb 12, 2025

Choose a reason for hiding this comment

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

Do you mean ?

function tryRequestAnimationFrame(fn: Fn) {
  if (typeof requestAnimationFrame === 'function') {
    requestAnimationFrame(fn)
  }
  else {
    fn()
  }
}
function tryRequestAnimationFrame(window, fn) {
  if (typeof window?.requestAnimationFrame === 'function') {
    window.requestAnimationFrame(fn)
  }
  else {
    fn()
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we could add this to #4548 and replace all instances with this, if needed.

Copy link
Member

Choose a reason for hiding this comment

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

Do we have other usage like this? If not I think we could just implement this inline for now and refactor later if needed

Copy link
Member Author

@ilyaliao ilyaliao Feb 14, 2025

Choose a reason for hiding this comment

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

Do we have other usage like this? If not I think we could just implement this inline for now and refactor later if needed

Maybe there isn't, but I think we can implement it directly.

Co-authored-by: Robin <37191683+OrbisK@users.noreply.github.com>
@ilyaliao ilyaliao dismissed stale reviews from antfu and OrbisK via 45a0e6d February 14, 2025 13:18
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 14, 2025
@ilyaliao ilyaliao requested review from OrbisK and antfu February 14, 2025 13:29
OrbisK
OrbisK previously approved these changes Feb 14, 2025
@antfu antfu disabled auto-merge February 15, 2025 09:08
@antfu antfu merged commit e1a7ef3 into vueuse:main Feb 15, 2025
7 of 8 checks passed
@ilyaliao ilyaliao deleted the fix/issue-4556 branch February 15, 2025 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG | useTextareaAutosize | "Uncaught ResizeObserver loop completed with undelivered notifications"
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.