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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Input] Failed to execute 'getComputedStyle' on 'Window' when suspense triggers on react 18 #32640

Closed
2 tasks done
voliva opened this issue May 5, 2022 · 2 comments 路 Fixed by #33238
Closed
2 tasks done
Assignees
Labels
bug 馃悰 Something doesn't work component: TextareaAutosize The React component. good first issue Great for first contributions. Enable to learn the contribution process.

Comments

@voliva
Copy link

voliva commented May 5, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 馃槸

When React 18.0.0 triggers a Suspense that hides a mounted <Input multiline />, TextareaAutosize @ syncHeight throws the following uncaught exception:

TextareaAutosize.js:42 Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
    at eval (TextareaAutosize.js:42:43)
    at ResizeObserver.eval (TextareaAutosize.js:87:7)
    at later (debounce.js:9:12)

It seems like the exception can be ignored, but react dev server shows the uncaught exception window.

Expected behavior 馃

<Input multiline /> should not throw exceptions when it enters suspense.

Steps to reproduce 馃暪

Steps:

  1. Open sandbox https://codesandbox.io/s/eager-hertz-6g658v?file=/src/app.js
  2. Click on "Toggle View" button
  3. // The app momentarily enters suspense loading the lazy route
  4. // The exception is shown

For future reference, sandbox code:

import { Input, Button } from '@mui/material';
import { Suspense, useState, lazy } from 'react';

const LazyRoute = lazy(async () => {
  // Force react to show fallback suspense
  await new Promise(resolve => setTimeout(resolve, 1000));
  return import('./lazyRoute');
});

export function App() {
  const [showRoute, setShowRoute] = useState(false);

  return <Suspense fallback={null}>
    <Button onClick={() => setShowRoute(r => !r)}>Toggle view</Button>
    <hr />
    { showRoute ? <LazyRoute /> : <Input multiline inputProps={{ minRows: 4 }} defaultValue="Text" /> }
  </Suspense>
}

Context 馃敠

When upgrading existing application to react 18, after changing from one route that has an <Input multiline> to another one

Your environment 馃寧

No response

@voliva voliva added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 5, 2022
@danilo-leal danilo-leal added the component: text field This is the name of the generic UI component, not the React module! label May 10, 2022
@oliviertassinari oliviertassinari added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 10, 2022
@dkadrios
Copy link

dkadrios commented Jun 2, 2022

Nothing to add except to say we're running into the same issue -- hoping it gets triaged 馃馃徑

@siriwatknp siriwatknp added bug 馃悰 Something doesn't work component: TextareaAutosize The React component. and removed component: text field This is the name of the generic UI component, not the React module! status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 20, 2022
@siriwatknp
Copy link
Member

I think the fix could be very simple, just return if there is no input html.

diff --git a/packages/mui-base/src/TextareaAutosize/TextareaAutosize.js b/packages/mui-base/src/TextareaAutosize/TextareaAutosize.js
index f3e4cdbc22..a986c37565 100644
--- a/packages/mui-base/src/TextareaAutosize/TextareaAutosize.js
+++ b/packages/mui-base/src/TextareaAutosize/TextareaAutosize.js
@@ -39,6 +39,9 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(props, ref)
 
   const syncHeight = React.useCallback(() => {
     const input = inputRef.current;
+    if (!input) {
+      return;
+    }
     const containerWindow = ownerWindow(input);
     const computedStyle = containerWindow.getComputedStyle(input);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 馃悰 Something doesn't work component: TextareaAutosize The React component. good first issue Great for first contributions. Enable to learn the contribution process.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants