-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[material-ui][TextareaAutosize] Temporarily disconnect ResizeObserver to avoid loop error #44540
Conversation
e712092
to
e2d5825
Compare
Netlify deploy previewhttps://deploy-preview-44540--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
b152a03
to
72a6aaa
Compare
72a6aaa
to
d140f30
Compare
d140f30
to
044a802
Compare
@@ -36,15 +36,20 @@ type TextareaStyles = { | |||
overflowing: boolean; | |||
}; | |||
|
|||
function isObjectEmpty(object: TextareaStyles) { |
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.
We can expose an util for this and share it in the different packages.
5b99446
to
3a7aaf2
Compare
@mj12albert since this was hard to reproduce and might have some edge cases, can you add a comment in the related issue (#43718) to see if some users can test with this PR's version? They'd need to install |
Added ~ #43718 (comment) |
e2af729
to
cdaa830
Compare
d84fef6
to
239b54b
Compare
239b54b
to
5196ed1
Compare
5196ed1
to
1e81206
Compare
@mj12albert no responses in #43718 (comment) so let's try to move this forward and see if the reports stop. @mnajdova and @DiegoAndai can you review this? |
cbf8a4a
to
9e4b8e9
Compare
Finally got one! 😅 |
9e4b8e9
to
91b919f
Compare
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 think we can try the fix, I can't 100% reproduce it, so I can't confirm for sure that it is fixed, but having a user confirm that the commit works sounds promising. Let's try it and see.
packages/mui-material/src/TextareaAutosize/TextareaAutosize.tsx
Outdated
Show resolved
Hide resolved
|
||
containerWindow.addEventListener('resize', debounceHandleResize); | ||
|
||
let resizeObserver: ResizeObserver; | ||
|
||
if (typeof ResizeObserver !== 'undefined') { | ||
resizeObserver = new ResizeObserver( | ||
process.env.NODE_ENV === 'test' ? rAFHandleResize : handleResize, |
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 why we only usedrequestAnimationFrame
for the test environment before this change 🤔
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.
Probably it triggers more frequently or consistently in tests envs?
If we actually used it though I suspect it would cause some jankiness: https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded#comment118281231_58701523
@DiegoAndai Hey, is this going to be added to v5 as well? Thanks |
Fixes #43718
Fixes #44140
Demo: https://codesandbox.io/p/sandbox/immutable-architecture-nslxvr?file=%2Fsrc%2FApp.js%3A33%2C1 (forked from the original repro)
This was very hard to repro locally, but I believe the "loop" is caused when we change the height of the element in the RO callback, while it is still being observed, which fires the callback again (and again…)
The fix is to un-observe the element, manipulate the height then re-observe one frame later, instead of manipulating the height one frame later suggested here (or here).