Skip to content
Snippets Groups Projects
Commit caf93856 authored by unarist's avatar unarist Committed by Eugen Rochko
Browse files

Avoid async import if the component is previously loaded (#4127)

parent ce3a371e
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,8 @@ class Bundle extends React.Component {
onFetchFail: noop,
}
static cache = {}
state = {
mod: undefined,
forceRender: false,
......@@ -58,8 +60,17 @@ class Bundle extends React.Component {
this.timeout = setTimeout(() => this.setState({ forceRender: true }), renderDelay);
}
if (Bundle.cache[fetchComponent.name]) {
const mod = Bundle.cache[fetchComponent.name];
this.setState({ mod: mod.default });
onFetchSuccess();
return Promise.resolve();
}
return fetchComponent()
.then((mod) => {
Bundle.cache[fetchComponent.name] = mod;
this.setState({ mod: mod.default });
onFetchSuccess();
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment