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

Fix: Multiline TextField unstable height (#36866) #5

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions packages/mui-base/src/TextareaAutosize/TextareaAutosize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
const handleResize = debounce(() => {
renders.current = 0;

// If the TextareaAutosize component is replaced by Suspense with a fallback, the last
// ResizeObserver's handler that runs because of the change in the layout is trying to
// access a dom node that is no longer there (as the fallback component is being shown instead).
// See https://github.com/mui/material-ui/issues/32640
if (inputRef.current) {
syncHeightWithFlushSync();
}
}, 0);
const handleResizeWindow = debounce(() => {
renders.current = 0;

// If the TextareaAutosize component is replaced by Suspense with a fallback, the last
// ResizeObserver's handler that runs because of the change in the layout is trying to
// access a dom node that is no longer there (as the fallback component is being shown instead).
Expand All @@ -201,7 +212,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
const input = inputRef.current!;
const containerWindow = ownerWindow(input);

containerWindow.addEventListener('resize', handleResize);
containerWindow.addEventListener('resize', handleResizeWindow);

if (typeof ResizeObserver !== 'undefined') {
resizeObserver = new ResizeObserver(handleResize);
Expand All @@ -210,7 +221,8 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(

return () => {
handleResize.clear();
containerWindow.removeEventListener('resize', handleResize);
handleResizeWindow.clear();
containerWindow.removeEventListener('resize', handleResizeWindow);
if (resizeObserver) {
resizeObserver.disconnect();
}
Expand Down