🐛 just prefetch the apps which not loaded, rather than the loading or loaded error ones (#980)
This commit is contained in:
parent
b57f94cff1
commit
0564c00236
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
import { Entry, importEntry, ImportEntryOpts } from 'import-html-entry';
|
import { Entry, importEntry, ImportEntryOpts } from 'import-html-entry';
|
||||||
import { isFunction } from 'lodash';
|
import { isFunction } from 'lodash';
|
||||||
import { getMountedApps } from 'single-spa';
|
import { getAppStatus, getMountedApps, NOT_LOADED } from 'single-spa';
|
||||||
import { AppMetadata, PrefetchStrategy } from './interfaces';
|
import { AppMetadata, PrefetchStrategy } from './interfaces';
|
||||||
|
|
||||||
type RequestIdleCallbackHandle = any;
|
type RequestIdleCallbackHandle = any;
|
||||||
|
|
@ -77,14 +77,14 @@ function prefetch(entry: Entry, opts?: ImportEntryOpts): void {
|
||||||
|
|
||||||
function prefetchAfterFirstMounted(apps: AppMetadata[], opts?: ImportEntryOpts): void {
|
function prefetchAfterFirstMounted(apps: AppMetadata[], opts?: ImportEntryOpts): void {
|
||||||
window.addEventListener('single-spa:first-mount', function listener() {
|
window.addEventListener('single-spa:first-mount', function listener() {
|
||||||
const mountedApps = getMountedApps();
|
const notLoadedApps = apps.filter(app => getAppStatus(app.name) === NOT_LOADED);
|
||||||
const notMountedApps = apps.filter(app => mountedApps.indexOf(app.name) === -1);
|
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'development') {
|
if (process.env.NODE_ENV === 'development') {
|
||||||
console.log(`[qiankun] prefetch starting after ${mountedApps} mounted...`, notMountedApps);
|
const mountedApps = getMountedApps();
|
||||||
|
console.log(`[qiankun] prefetch starting after ${mountedApps} mounted...`, notLoadedApps);
|
||||||
}
|
}
|
||||||
|
|
||||||
notMountedApps.forEach(({ entry }) => prefetch(entry, opts));
|
notLoadedApps.forEach(({ entry }) => prefetch(entry, opts));
|
||||||
|
|
||||||
window.removeEventListener('single-spa:first-mount', listener);
|
window.removeEventListener('single-spa:first-mount', listener);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user