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

[material-ui] Accessing element.ref was removed in React 19 #42604

Closed
Tracked by #42381
oliviertassinari opened this issue Jun 10, 2024 · 3 comments · Fixed by #42818 or #43132
Closed
Tracked by #42381

[material-ui] Accessing element.ref was removed in React 19 #42604

oliviertassinari opened this issue Jun 10, 2024 · 3 comments · Fixed by #42818 or #43132
Assignees
Labels
bug 🐛 Something doesn't work component: tooltip This is the name of the generic UI component, not the React module! React 19 support PRs required to support React 19

Comments

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 10, 2024

In React 19, ref is now a prop and should be accessed through props.ref. We have some instances of this we should fix: https://github.com/search?q=repo:mui/material-ui%20children.ref&type=code

Example with Tooltip

https://codesandbox.io/p/sandbox/silly-sea-m9cjyn?file=%2Fsrc%2FDemo.tsx

import * as React from "react";
import Tooltip from "@mui/material/Tooltip";

export default function BasicTooltip() {
  const ref = React.useRef();
  return (
    <Tooltip title="Delete">
      <button ref={ref}>hello</button>
    </Tooltip>
  );
}
SCR-20240610-pupd

Warning: Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.
at Tooltip (node_modules/@mui/material/Tooltip/Tooltip.js:294:85)

Context

const handleRef = useForkRef(children.ref, focusVisibleRef, setChildNode, ref);

Your environment

react v19.0.0-rc.0
@mui/material v5.15.19

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work component: tooltip 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 10, 2024
@DiegoAndai DiegoAndai self-assigned this Jun 10, 2024
@DiegoAndai DiegoAndai removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 10, 2024
@DiegoAndai DiegoAndai changed the title [react 19][tooltip] Accessing element.ref was removed in React 19 [material-ui] Accessing element.ref was removed in React 19 Jul 2, 2024
@DiegoAndai
Copy link
Member

Updated issue so it covers all cases and not only the Tooltip one.

@luc-nham
Copy link

luc-nham commented Jul 18, 2024

The Select component also appears the warning. My environment:

  • React 19 Canary
  • Material UI v5.x

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Jul 18, 2024

The Select component also appears the warning

@luc-nham Right, we solved some of the instances of the issue but we didn't solve the issue. There are still hits for this: https://github.com/search?q=repo%3Amui%2Fmaterial-ui%20children.ref&type=code.


Actually, we have 3 times the same components, so 3 times the same fix to apply?

At first sight, it doesn't seem to make sense, what's the direction?

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: tooltip This is the name of the generic UI component, not the React module! React 19 support PRs required to support React 19
Projects
None yet
3 participants