Skip to content
Extraits de code Groupes Projets
Valider 7cb49eaa rédigé par Akihiko Odaki's avatar Akihiko Odaki Validation de Eugen Rochko
Parcourir les fichiers

Do not use function name to track components (#6542)

UglifyJS2 is allowed to mangle function names, and function names can also
be duplicate if they are from different scopes. Therefore function names
are not reliable as identifiers.

Functions as keys for Map object is a cheaper and more reliable
alternative.
parent 4d8c0d99
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -26,7 +26,7 @@ class Bundle extends React.Component {
onFetchFail: noop,
}
static cache = {}
static cache = new Map
state = {
mod: undefined,
......@@ -51,13 +51,12 @@ class Bundle extends React.Component {
load = (props) => {
const { fetchComponent, onFetch, onFetchSuccess, onFetchFail, renderDelay } = props || this.props;
const cachedMod = Bundle.cache.get(fetchComponent);
onFetch();
if (Bundle.cache[fetchComponent.name]) {
const mod = Bundle.cache[fetchComponent.name];
this.setState({ mod: mod.default });
if (cachedMod) {
this.setState({ mod: cachedMod.default });
onFetchSuccess();
return Promise.resolve();
}
......@@ -71,7 +70,7 @@ class Bundle extends React.Component {
return fetchComponent()
.then((mod) => {
Bundle.cache[fetchComponent.name] = mod;
Bundle.cache.set(fetchComponent, mod);
this.setState({ mod: mod.default });
onFetchSuccess();
})
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter