-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
An exception is thrown when using Mobx6 and react18 in development mode #3492
An exception is thrown when using Mobx6 and react18 in development mode #3492
Comments
Please create a runnable reproduction using codesandbox. Here is an example of Mobx + React 18 that shows no warnings: https://codesandbox.io/s/vigilant-hellman-3mjsty?file=/index.js |
@kubk hello, this is the demo code link. https://codesandbox.io/s/mobx6-and-react18-2rx40e?file=/index.js |
and in this case, this problem can also be reproduced by clicking the button, https://codesandbox.io/s/mobx6-and-react18-2-gu58ts?file=/CompA.js |
@guochengcheng04 please remove this comment. It is rude, and completely uncalled for within four hours. This software is provided to you as-is, and people are helping out here on a voluntarily basis, to help you with the problems you are probably paid to solve. So please refrain from such comments, and if you want to increase your chance on follow up, consider instead contributing to the community yourself, by helping out others with their issues. |
sorry, my bad. because this problem is stable and recurring, and it is important |
@mweststrate We will have to handle reaction disposal of class components similary to functional ones. Apparently react can now decide to run render and throw the component instance away without running lifecycle methods. It does it when using |
@urugator If you can provide me with some ideas, I think I'd be happy to solve it |
@guochengcheng04 If you mean to PR, then you will have to take a look at: mobx/packages/mobx-react-lite/src/useObserver.ts Lines 5 to 7 in 28e080e
Then the goal is to make use of these in a similar fashion in observerClass :https://github.com/mobxjs/mobx/blob/main/packages/mobx-react/src/observerClass.ts If you mean what you can do in your code base, then you can rewrite components using function SuspenseWorkaround(...props) {
return <Suspense {...props}></Suspense>
}
const root = createRoot(document.getElementById("root"));
root.render(
<SuspenseWorkaround fallback={<div id="outer-loading" />}>
<CompA />
</SuspenseWorkaround>
); |
@urugator Can we use |
and I checked the implementation of the function component you said. It may not be applicable to class components, because |
It's only part of the solution, same as here: mobx/packages/mobx-react-lite/src/useObserver.ts Lines 49 to 51 in f0e066f
No it's exactly what it tries to solve: |
@urugator I mean, like the code in the figure, in the function component scenario, we can assign a value to |
Why? Once the |
https://codesandbox.io/s/mobx6-and-react18-2-gu58ts?file=/CompA.js @urugator Look at this output. |
@guochengcheng04 Yes because |
@urugator so the idea is still to associate the mock |
@urugator I implemented the logic of the class component according to the idea of the function component, and the verification passed, please help to see if there is any problem, expect your approval |
I have completed the repair and verification of this issue, can any maintainer help me merge and publish it? |
Intended outcome:
When I use React18's new rendering API
ReactDOM.createRoot().render
, I get a lot of warnings. It should be guaranteed to be consistent with the previous behavior, run normally, and not throw warningswarning message: react_devtools_backend.js:3973 Warning: Can't perform a React state update on a component that hasn't mounted yet. This indicates that you have a side-effect in your render function that asynchronously later calls tries to update the component. Move this work to useEffect instead.
Actual outcome:
I get a lot of warnings, but can't find the information I have in it, like below
Versions
mobx@^6.6.1 mobx-react@^7.5.1
The text was updated successfully, but these errors were encountered: