Skip to content

Commit c7ad3ce

Browse files
committed
feat(module-loader): run outside of angular and in requestIdleCallback
1 parent 7dfe061 commit c7ad3ce

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ export class IonicModule {
594594
{ provide: APP_INITIALIZER, useFactory: registerModeConfigs, deps: [ Config ], multi: true },
595595
{ provide: APP_INITIALIZER, useFactory: setupProvideEvents, deps: [ Platform, DomController ], multi: true },
596596
{ provide: APP_INITIALIZER, useFactory: setupTapClick, deps: [ Config, Platform, DomController, App, NgZone, GestureController ], multi: true },
597-
{ provide: APP_INITIALIZER, useFactory: setupPreloading, deps: [ Config, DeepLinkConfigToken, ModuleLoader ], multi: true },
597+
{ provide: APP_INITIALIZER, useFactory: setupPreloading, deps: [ Config, DeepLinkConfigToken, ModuleLoader, NgZone ], multi: true },
598598

599599
// useClass
600600
// { provide: HAMMER_GESTURE_CONFIG, useClass: IonicGestureConfig },

src/util/module-loader.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ComponentFactoryResolver, Injectable, Injector, NgModuleFactory, OpaqueToken, Type } from '@angular/core';
1+
import { ComponentFactoryResolver, Injectable, Injector, NgModuleFactory, NgZone, OpaqueToken, Type } from '@angular/core';
22
import { Config } from '../config/config';
33
import { DeepLinkConfig } from '../navigation/nav-util';
44
import { NgModuleLoader } from './ng-module-loader';
5+
import { requestIonicCallback } from './util';
56

67
export const LAZY_LOADED_TOKEN = new OpaqueToken('LZYCMP');
78

@@ -76,9 +77,8 @@ export interface LoadedModule {
7677
/**
7778
* @private
7879
*/
79-
export function setupPreloading(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader) {
80-
return function() {
81-
if (config.getBoolean('preloadModules')) {
80+
export function setupPreloadingImplementation(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader) {
81+
if (config.getBoolean('preloadModules')) {
8282
const linksToLoad = deepLinkConfig.links.filter(link => !!link.loadChildren && link.priority !== 'off');
8383

8484
// Load the high priority modules first
@@ -100,5 +100,17 @@ export function setupPreloading(config: Config, deepLinkConfig: DeepLinkConfig,
100100
console.error(err.message);
101101
});
102102
}
103+
}
104+
105+
/**
106+
* @private
107+
*/
108+
export function setupPreloading(config: Config, deepLinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader, ngZone: NgZone) {
109+
return function() {
110+
requestIonicCallback(() => {
111+
ngZone.runOutsideAngular(() => {
112+
setupPreloadingImplementation(config, deepLinkConfig, moduleLoader);
113+
});
114+
});
103115
};
104116
}

0 commit comments

Comments
 (0)