Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions packages/core/src/platform/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {InjectionToken, Injector} from '../di';
import {InternalNgModuleRef, NgModuleRef} from '../linker/ng_module_factory';
import {stringify} from '../util/stringify';
import {isPromise} from '../util/lang';
import {PendingTasksInternal} from '../pending_tasks';

/**
* InjectionToken to control root component bootstrap behavior.
Expand Down Expand Up @@ -132,38 +133,47 @@ export function bootstrap<M>(
}

return _callAndReportToErrorHandler(exceptionHandler, ngZone, () => {
const pendingTasks = envInjector.get(PendingTasksInternal);
const taskId = pendingTasks.add();
const initStatus = envInjector.get(ApplicationInitStatus);
initStatus.runInitializers();

return initStatus.donePromise.then(() => {
// If the `LOCALE_ID` provider is defined at bootstrap then we set the value for ivy
const localeId = envInjector.get(LOCALE_ID, DEFAULT_LOCALE_ID);
setLocaleId(localeId || DEFAULT_LOCALE_ID);

const enableRootComponentBoostrap = envInjector.get(ENABLE_ROOT_COMPONENT_BOOTSTRAP, true);
if (!enableRootComponentBoostrap) {
if (isApplicationBootstrapConfig(config)) {
return envInjector.get(ApplicationRef);
try {
// If the `LOCALE_ID` provider is defined at bootstrap then we set the value for ivy
const localeId = envInjector.get(LOCALE_ID, DEFAULT_LOCALE_ID);
setLocaleId(localeId || DEFAULT_LOCALE_ID);

const enableRootComponentBoostrap = envInjector.get(
ENABLE_ROOT_COMPONENT_BOOTSTRAP,
true,
);
if (!enableRootComponentBoostrap) {
if (isApplicationBootstrapConfig(config)) {
return envInjector.get(ApplicationRef);
}

config.allPlatformModules.push(config.moduleRef);
return config.moduleRef;
}

config.allPlatformModules.push(config.moduleRef);
return config.moduleRef;
}

if (typeof ngDevMode === 'undefined' || ngDevMode) {
const imagePerformanceService = envInjector.get(ImagePerformanceWarning);
imagePerformanceService.start();
}
if (typeof ngDevMode === 'undefined' || ngDevMode) {
const imagePerformanceService = envInjector.get(ImagePerformanceWarning);
imagePerformanceService.start();
}

if (isApplicationBootstrapConfig(config)) {
const appRef = envInjector.get(ApplicationRef);
if (config.rootComponent !== undefined) {
appRef.bootstrap(config.rootComponent);
if (isApplicationBootstrapConfig(config)) {
const appRef = envInjector.get(ApplicationRef);
if (config.rootComponent !== undefined) {
appRef.bootstrap(config.rootComponent);
}
return appRef;
} else {
moduleBootstrapImpl?.(config.moduleRef, config.allPlatformModules);
return config.moduleRef;
}
return appRef;
} else {
moduleBootstrapImpl?.(config.moduleRef, config.allPlatformModules);
return config.moduleRef;
} finally {
pendingTasks.remove(taskId);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/platform-server/test/dom_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ export function hydrate(
global.document = doc;

const providers = [
...envProviders,
{provide: PLATFORM_ID, useValue: 'browser'},
{provide: DOCUMENT, useFactory: () => doc},
provideClientHydration(...hydrationFeatures()),
...envProviders,
];

return bootstrapApplication(component, {providers});
Expand Down