Ref callback cleanup functions for MUI components are not invoked in React 19 #45538
Labels
package: material-ui
Specific to @mui/material
React 19 support
About improving React 19 support
status: waiting for maintainer
These issues haven't been looked at yet by a maintainer
Steps to reproduce
Steps:
Current behavior
A MUI component that is passed a ref callback function which returns a cleanup function does not have its cleanup function invoked when the component is unmounted. It instead passes null to callback function.
Expected behavior
Material components with ref callback functions that return a cleanup function should properly execute the cleanup function when the component is unmounted.
See https://react.dev/reference/react-dom/components/common#ref-callback.
Context
I have a list of search results, where each result item includes a checkbox. I have a context that tracks state of number selected, the selected values, and an array of all of the checkboxes that are mounted. The state is maintained with a reducer.
I want to use the ref cleanup function to remove this element from the tracked state data.
Your environment
npx @mui/envinfo
Search keywords: ref callback cleanup react 19
The text was updated successfully, but these errors were encountered: