Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions packages/mui-base/src/TextareaAutosize/TextareaAutosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)
// 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
// TODO: Add tests that will ensure the component is not failing when
// replaced by Suspense with a fallback, once React is updated to version 18
if (inputRef.current) {
syncHeightWithFlushSycn();
}
Expand Down
30 changes: 30 additions & 0 deletions test/e2e/fixtures/TextareaAutosize/TextareaAutosizeSuspense.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import TextareaAutosize from '@mui/base/TextareaAutosize';
import Button from '@mui/material/Button';
import * as React from 'react';

function LazyRoute() {
const [isDone, setIsDone] = React.useState(false);

if (!isDone) {
// Force React to show fallback suspense
throw new Promise((resolve) => {
window.setTimeout(resolve, 1);
setIsDone(true);
});
}

return <div />;
}

export default function TextareaAutosizeSuspense() {
const [showRoute, setShowRoute] = React.useState(false);

return (
<React.Fragment>
<Button onClick={() => setShowRoute((r) => !r)}>Toggle view</Button>
<React.Suspense fallback={null}>
{showRoute ? <LazyRoute /> : <TextareaAutosize />}
</React.Suspense>
</React.Fragment>
);
}
4 changes: 3 additions & 1 deletion test/e2e/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { createRoot } from 'react-dom/client';
import { BrowserRouter as Router, Routes, Route, Link } from 'react-router-dom';
import * as DomTestingLibrary from '@testing-library/dom';
import TestViewer from './TestViewer';
Expand Down Expand Up @@ -107,7 +108,8 @@ if (typeof ReactDOM.unstable_createRoot === 'function') {
const root = ReactDOM.unstable_createRoot(container);
root.render(children);
} else {
ReactDOM.render(children, container);
const root = createRoot(container);
root.render(children);
}

window.DomTestingLibrary = DomTestingLibrary;
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,20 @@ describe('e2e', () => {
);
});
});

describe('<TextareaAutosize />', () => {
// https://github.com/mui/material-ui/issues/32640
it('should handle suspense without error', async () => {
const pageErrors: string[] = [];
page.on('pageerror', (err) => pageErrors.push(err.name));

await renderFixture('TextareaAutosize/TextareaAutosizeSuspense');
expect(await page.isVisible('textarea')).to.equal(true);
await page.click('button');
expect(await page.isVisible('textarea')).to.equal(false);
await page.waitForTimeout(200); // Wait for debounce to fire (166)

expect(pageErrors.length).to.equal(0);
});
});
});