-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
Description
Steps to reproduce
minimal code example:
import React, { createRef } from 'react';
import { createRoot } from 'react-dom/client';
import Select from '@mui/material/Select';
import MenuItem from '@mui/material/MenuItem';
class MyCustomElement extends HTMLElement {
connectedCallback() {
this._root = createRoot(this);
this._root.render(<MySelect />);
}
disconnectedCallback() {
this._root.unmount();
}
}
const MySelect = () => {
const [value, setValue] = React.useState('');
const ref = createRef();
return (
<Select
value={value}
onChange={(e) => setValue(e.target.value)}
inputRef={ref}
>
<MenuItem value="one">One</MenuItem>
<MenuItem value="two">Two</MenuItem>
</Select>
);
};
customElements.define('my-custom-element', MyCustomElement);
Current behavior
When using MUI Select inside a custom HTMLElement with React createRoot(this) opening the Select causes the page to freeze and throws:
useTimeout.js:25 Uncaught TypeError: fn is not a function
This appears to be related to MUI Select relying on Popover + Grow + internal refs, which break when the component is rendered directly inside a custom element.
using transitionDuration={0} into MenuProps fixes the issue, but it's not ideal
Expected behavior
The Select dropdown should open without freezing, similar to how Popover works in a stable container.
Context
No response
Your environment
npx @mui/envinfo
System:
OS: macOS 14.6.1
Binaries:
Node: 20.8.0 - /Users/patriciaromaniuc/.nvm/versions/node/v20.8.0/bin/node
npm: 10.1.0 - /Users/patriciaromaniuc/.nvm/versions/node/v20.8.0/bin/npm
pnpm: 8.9.0 - /Users/patriciaromaniuc/.nvm/versions/node/v20.8.0/bin/pnpm
Browsers:
Chrome: 142.0.7444.60
Edge: Not Found
Firefox: 137.0
Safari: 18.3.1
npmPackages:
@emotion/react: 11.14.0
@emotion/styled: 11.14.1
@mui/core-downloads-tracker: 7.3.4
@mui/icons-material: 7.3.4
@mui/material: 7.3.4
@mui/types: 7.4.7
@types/react: 19.2.2
react: 18.2.0 => 18.2.0
react-dom: 18.2.0 => 18.2.0
styled-components: 5.3.11
typescript: 3.9.10
Search keywords: useTimeout, Select, Menu, Grow