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

Mobx is used with React.Lazy, the render method is executed many times when requesting data #3621

Closed
fx-2 opened this issue Feb 1, 2023 · 2 comments
Labels

Comments

@fx-2
Copy link

fx-2 commented Feb 1, 2023

Intended outcome: When Mobx is used with React.Lazy, and the request is sent in the action, the component will only render the expected number of times

Actual outcome: When Mobx is used with React.Lazy, if the request is sent and the variable is set in the action, the component using React.Lazy will execute the render method hundreds of times. this is not normal

How to reproduce the issue: Here is CodeSandbox example:
https://codesandbox.io/s/youthful-david-00hzul?file=/src/App.js
image

Versions
react 18.2.0
mobx-react 7.6.0
mobx 6.7.0

@fx-2 fx-2 added the 🐛 bug label Feb 1, 2023
@urugator
Copy link
Collaborator

urugator commented Feb 1, 2023

Hm not sure if you can call React.lazy directly in render. Can you move const Test = lazy(() => import("./Test")); outside the component?

Then the warning:

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.

relates to
#3492

and is addressed by
#3590

@fx-2
Copy link
Author

fx-2 commented Feb 2, 2023

ok. I moved React.lazy to the constructor method and this works fine. thanks

@fx-2 fx-2 closed this as completed Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants