mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-30 12:09:04 +01:00
Avoid async import if the component is previously loaded (#4127)
This commit is contained in:
parent
ce3a371eee
commit
caf938562e
1 changed files with 11 additions and 0 deletions
|
@ -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();
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue