-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
Warnings in strict mode #13394
Comments
We can't get rid of findDOMNode in many cases as I pointed out previously: #13221 (comment) Is there currently a way to check from a component if it is in StrictMode? That way we could avoid findDOMNode and somehow communicate to users that their components should properly forward their refs. The context API rewrite should hopefully not cause any breakage but I'm not very familiar with our theming approach. |
It seems that you need to have access to the current fiber in process : https://github.com/facebook/react/blob/master/packages/react-reconciler/src/ReactFiberBeginWork.js#L946-L948 though, this will be a common need for library authors. |
I think that line is about context. So I looked at the code of findDOMNode and did some testing and it turns out that React does not warn if you pass a dom Example: https://codesandbox.io/s/qko6n6vzjj |
Just to be clear, it currently works with Suspense (this is the Async rendering part which might pose problem - like Time Slicing). Your example is perfect 👍- at least we know that there is an escape hatch anyway. However, this means, that each time the user passes a Example: <Toolbar>
<Button
component={Link}
to="/"
title="Home"
/>
<IconButton
component={Link}
to="/foo"
title="Foo"
/>
<Typography
component={Link}
to="/"
title="Bar"
>
Bar
</Typography>
</Toolbar> |
@topheman Might be a good idea to add a note to the documentation where people can pass their own component and we use We could also issue deprecation warnings if Also the react docs recommend using |
If you pass a DOM element, why do you need |
@gaearon interface Props {
as: React.ComponentClass | React.ForwardRefExoticComponent | string;
}
function Button({ as: Component }: Props) {
// users in strict mode would be required to forward refs to the DOM node
// while users in "loose" mode can simply pass in anything that can hold refs
return <Component ref={ref => findDOMNode(ref)!.focus()} />
}
// valid
<Button as="div" />
<Button as={SomeClassComponent} />
<Button as={SomeComponentThatForwardsRefs} />
<Button as={ReactRouterLink} />
// invalid but was valid via findDOMNode(this) in the Button implemented as a class component
<Button as={() => <ReactRouterLink to="/somewhere" />} /> |
Tracking progress here.
|
An update on our current progress. We have solved most the issue in Material-UI. We dependent on reactjs/react-transition-group#429 to be 100% compliant. |
since with version mui has solved most strict issues? |
@sibelius v4.5.1 is a safe bet 😁. |
@topheman Do you know if this is still an issue in v5 beta? |
Looking at the results of https://github.com/mui-org/material-ui/search?q=StrictModeViolation. It seems that we are done. The instances where it fails are related to the soon-to-be deprecated |
Public documentation that these methods are neither StrictMode nor React 18 compatible is missing. Then we can close. For StrictMode issues in React 18 I would start a new issue. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
With the release of v5 (release candidate next week) all Happy to close this issue before its 3 year anniversary and thank you for your patience. |
EDIT: For the developers that feel adventurous, they can try:
It's available since #20523, v4.9.11, our intended version for v5. You can find the documentation at https://material-ui.com/customization/theming/#unstable-createmuistrictmodetheme-options-args-theme.
I am playing with Suspense on my project topheman/react-fiber-experiments. I have the following warnings in development:
The Suspense part (asynchronous fetching, placeholders ...) works ok out of strict mode - check the demo.
Though, the async render part (time slicing) may need strict mode (check the link bellow). This is something to dig into now, people will soon be trying alphas of Suspense and a new major version of react will come in a few months.
Resource to read
Related: Migrate from findDOMNode to refs
Your Environment
More infos:
The text was updated successfully, but these errors were encountered: