-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[data grid] React 19 - everything that depends on GridRootPropsContext
re-renders on every state change (or root re-render) if the ref prop is present
#15770
Comments
GridRootPropsContext
re-renders if ref prop is presentGridRootPropsContext
re-renders on ever state change if ref prop is present
GridRootPropsContext
re-renders on ever state change if ref prop is presentGridRootPropsContext
re-renders on every state change (or root re-render) if the ref prop is present
Thanks for opening it @lauri865 ... you're adopting R19 pretty swiftly, very nice! I'll forward it to the team and add it to the board! 👍🏼 |
GridRootPropsContext
re-renders on every state change (or root re-render) if the ref prop is presentGridRootPropsContext
re-renders on every state change (or root re-render) if the ref prop is present
It looks like there's nothing we can do about it on our side until it's fixed in React 😕 |
A breaking fix on Datagrid's end in I wouldn't hold my breath waiting after React 🙊 Fwiw, we're just running a locally patched version of the Datagrid that strips out the |
If React doesn't fix it, then yes the |
Alternatively, maybe something like that could work? const forwardRefBackwardsCompatible = <T, P>(
render: React.ForwardRefRenderFunction<T, P>,
) => {
if (React.version.startsWith("19")) {
const Component = (props: any) => render(props, props.ref ?? null);
return Component;
}
return React.forwardRef(render);
}; If it works, it'd probably be more performant than creating a new object on every render in React 19 and then trying to memoize it / shallow compare it. |
And a reason why I wouldn't count on an upstream change is that the fix would likely mean breaking the below pattern: const Test = React.forwardRef((props, refProp) => {
const internalRef = React.useRef(null);
const ref = useMergedRef(refProp, internalRef);
return <div ref={ref} {...props}>Test</div>;
})
<Test ref={React.useRef()} /> Internal Still, it should come with a big fat red warning label though, as the new behaviour is very unclear and undocumented. |
I would call this an antipattern, cause this is quite naive to specify overrides prior to a spread operator. If such exists in mui code it must be refactored IMHO |
Well, prior to React 19 it wasn't an override, as props could never contain a ref. Now it is. Which is the core reason why this change exists in React. Agree that it should be removed in Mui if it exists going forward, but it doesn't change anything for upstream and the issue remains so long as forwardRef is used within React 19. |
I'm happy with that solution, and yes considering the facts it's likely React won't fix it, so we can go ahead with that. |
Search keywords
N/A
Latest version
Affected products
Data Grid
Steps to reproduce
Steps:
Current behavior
Read more about on the links above.
Found in the midst of another PR, so opening an issue so it doesn't go overlooked, especially now that there's official React 19 support and React 19 is stable.
Worth noting that it can also affect instances where developers don't actually provide a ref, but have created an abstracted component over the Datagrid which passes forward the ref prop by explicitly naming it as
ref={ref}
even ifref={undefined}
. This was the case for us. Which means that the potential share of users affected is much wider.Not sure if the problem affects any other areas of the DataGrid as well, but probably not as critical as this.
cc @arminmeh, since you worked on the React 19 support
The text was updated successfully, but these errors were encountered: