-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
textareaOldWidth.value = contentRect.width | ||
triggerResize() | ||
|
||
requestAnimationFrame(() => { |
There was a problem hiding this comment.
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
😄
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
textareaOldWidth.value = contentRect.width | ||
triggerResize() | ||
|
||
window?.requestAnimationFrame(() => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about tryRequestAnimationFrame
😄
There was a problem hiding this comment.
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()
}
}
There was a problem hiding this comment.
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()
}
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
fix: #4556
Before submitting the PR, please make sure you do the following
fixes #123
).Description
This PR fixes
ResizeObserver
loop errors by wrapping resize triggers inrequestAnimationFrame
.