Преглед на файлове

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

master
unarist преди 6 години
committed by Eugen Rochko
родител
ревизия
caf938562e
променени са 1 файла, в които са добавени 11 реда и са изтрити 0 реда
  1. +11
    -0
      app/javascript/mastodon/features/ui/components/bundle.js

+ 11
- 0
app/javascript/mastodon/features/ui/components/bundle.js Целия файл

@@ -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();
})


Зареждане…
Отказ
Запис