question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The browser crashes when use React.lazy return Promise.resolve(undefined)

See original GitHub issue

Do 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:open
  • Created 5 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
gaearoncommented, Mar 6, 2019

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).

2reactions
daychongyangcommented, Oct 11, 2019

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  (⊙ˍ⊙)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found