-
-
Notifications
You must be signed in to change notification settings - Fork 32.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
[material-ui] Lazy-loaded Collapse with unmountOnExit causes infinite loop #42457
Comments
Wrapping the code inside of collapse with Suspense also fixes the issue (lazy, i guess). But you don't get the very first transition, instead its pop ups. The issue seems to be caused by lazy. |
@tajbowness are you receiving these errors for all components or only those coming from I've been testing a bit and this is the summary is:
I'd always recommend wrapping lazy-loaded components in I think we should focus on a more realistic scenario like this one I adapted from your demo: playground. @siriwatknp @DiegoAndai do you remember similar issues with Material UI transition components? |
Hey @aarongarciah, thanks for the reply! This error that I mentioned earlier, Has only been occurring with
This has been the first time I've encountered this error. Having no initial transition isn't much of a concern. But I'm wondering now how to solve the other error ( |
@tajbowness can you provide a playground or repo where we can reproduce the |
@tajbowness this could be helpful/related #41960 (comment) |
@aarongarciah I've tried that, unfortunately, it still persists. I've made some changes and swapped from using lazy to I think you may be right with that it may be a CJS/ESM issue (My project is ESM). I am using Vite, which I believe it doesn't fully support CJS, but I've tried So I'm currently importing like this Doing this,
I'm unable to create a repo that reproduces the error, I know that's not very helpful, but it seems the issue is with Vite anyways. What do you think? I think this can be closed. |
I expect issues with Vite + CJS to go away once #30671 is completed cc @DiegoAndai. I'll rename this issue so we can track the problem with the initial animation when a component is lazy-loaded. |
Thinking about it a bit more, it makes sense the initial animation doesn't work because there is no content within |
Steps to reproduce
Link to live example: (required)
https://stackblitz.com/edit/react-cfhjx1?file=Demo.js
Steps:
Current behavior
Using unmountOnExit on collapse causes infinite loop.
Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
Removing
unmountOnExit
prop from collapse fixes issue. I'd like to useunmountonExit
though so I hope to find a solution.Lazy loading is also likely another reason why this issue is occuring. But for my project it's necessary otherwise, I'd get these prompts
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
Code is from MUI Docs only changed the imports as that is how my project is.
React / Remix / Vite
Expected behavior
Dropdown :)
Context
Dropdown :)
Your environment
https://stackblitz.com/edit/react-cfhjx1?file=Demo.js
Search keywords: Collapse Infinite unmountOnExit
The text was updated successfully, but these errors were encountered: