Further reduce code differences with upstream (#2509)

This commit is contained in:
Claire authored and GitHub committed 2023-12-09 20:29:23 +01:00
1 parent 1ddf2012ee
commit a27abb4802
15 files changed
+102 -109

No files matched your search

@@ -1,10 +1,10 @@
import PropTypes from 'prop-types';
import { Component } from 'react';
import { PureComponent } from 'react';
const emptyComponent = () => null;
const noop = () => { };
class Bundle extends Component {
class Bundle extends PureComponent {
static propTypes = {
fetchComponent: PropTypes.func.isRequired,
@@ -26,7 +26,7 @@ class Bundle extends Component {
onFetchFail: noop,
};
static cache = {};
static cache = new Map;
state = {
mod: undefined,
@@ -51,6 +51,7 @@ class Bundle extends Component {
load = (props) => {
const { fetchComponent, onFetch, onFetchSuccess, onFetchFail, renderDelay } = props || this.props;
const cachedMod = Bundle.cache.get(fetchComponent);
if (fetchComponent === undefined) {
this.setState({ mod: null });
@@ -59,10 +60,8 @@ class Bundle extends Component {
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();
}
@@ -76,7 +75,7 @@ class Bundle extends Component {
return fetchComponent()
.then((mod) => {
Bundle.cache[fetchComponent.name] = mod;
Bundle.cache.set(fetchComponent, mod);
this.setState({ mod: mod.default });
onFetchSuccess();
})