The browser crashes when use React.lazy return Promise.resolve(undefined)
See original GitHub issueDo you want to request a feature or report a bug? bug
What is the current behavior? The browser crashes
const Loading = () => <div>loading...</div>;
const Component = lazy(() => Promise.resolve(undefined));
function App() {
return (
<div className="App">
<Suspense fallback={<Loading />}>
<Component />
</Suspense>
</div>
);
}
I can’t provide an example of CodeSandbox, which would cause the browser to crash
What is the expected behavior? throw Error
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React? react@16.8.3 react-dom@16.8.3 chrome 72.0.3626.119
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Undefined Promise Error Lazy Loading Routes in React ...
I think the possibility of getting this error is by missing the default export in your Component which becomes a named export.
Read more >element type is invalid. received a promise that resolves to
The docs state that:. React.lazy takes a function that must call a dynamic import().This must return a Promise which resolves to a module...
Read more >Retry dynamic imports with “React.lazy” | by Alon Mizrahi
What will happen if the file cannot download at the time of navigation? the app will crash, as React.lazy failed to import.
Read more >A Trello feature froze, but engineering didn't: How we fixed an ...
I found this GitHub issue, which looked promising: The browser crashes when use React.lazy return Promise.resolve(undefined) · Issue #15019 ...
Read more >React v18.0 – React Blog
React guarantees that the UI will appear consistent even if a render is interrupted. To do this, it waits to perform DOM mutations...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok I see what you mean now. You’re saying React enters an infinite loop it lazy import resolves to undefined. That sounds like something we’d want to fix (even though it’s a bug in the application code).
I have the same problem after using React.lazy for code splitting, sometimes there is memory soaring, the page is unresponsive, and the console is madly reporting an error. Has this problem been solved in the current release? @gaearon @raunofreiberg (⊙ˍ⊙)