Handling failed dynamic imports
See original GitHub issueFeature request
Is your feature request related to a problem? Please describe.
Example: A website with lazy loading components. While scrolling down, your mobile internet might be cut off. Once you get to the bottom, parts of the website won’t be displayed because fetching the chunks failed. Those components will remain stuck in their loading state, even when internet connectivity is back.
Describe the solution you’d like
In our case we would like to catch the error and maybe display an error message and also a button that lets users try again on fetching the chunks.
const DynamicComponent = dynamic(
() => import("../../components/DynamicComponent"),
{
loading: () => <span>loading...</span>,
errorMsg: () => <span>Network interruption detected</span>,
retry: () => <button>Try again</button>,
},
);
Additional context
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Handling failed dynamic imports · Issue #10495 · vercel/next.js
Example: A website with lazy loading components. While scrolling down, your mobile internet might be cut off. Once you get to the bottom,...
Read more >What is the best practice for dealing with a failed dynamic ...
I use Webpack dynamic imports to split my bundle. In particular, I often use it with React.lazy like so const Component = React.lazy(() ......
Read more >How to Handle Dynamic Import Errors in Vuejs
Today, I'm going to talk about dynamic import error handling. ... In Vuejs, we can set import methods return value to component key...
Read more >Dynamic Import, Code Splitting, Lazy Loading, and Error ...
You will encounter the error: “Cannot find module with dynamic import.” This error comes from Webpack, which is used by Create React App....
Read more >Confusing error message when using dynamic import with ...
If I run import("./foo.js") where foo.js does not exist I already get a good error: TypeError: error loading dynamically imported module.
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 FreeTop 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
Top GitHub Comments
Wouldn’t this work?
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.