Skip to content

Commit 2fd1f7b

Browse files
crisbetoNothingEverHappens
authored andcommitted
fix(platform-browser): resolve component resources before bootstrapping in JIT mode (#62758)
Currently if the app has some external resources and it gets bootstrapped in JIT mode, the user will get an error about calling `resolveComponentResources`. These changes add a call to `resolveComponentResources` automatically inside `bootstrapApplication`. Note that we don't need similar logic for `bootstrapModule`, because it calls into `compileNgModuleFactory` internally which in turn calls `resolveComponentResources`. PR Close #62758
1 parent f38ee0d commit 2fd1f7b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/platform-browser/src/browser.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
ɵTESTABILITY as TESTABILITY,
3939
ɵTESTABILITY_GETTER as TESTABILITY_GETTER,
4040
inject,
41+
ɵresolveComponentResources as resolveComponentResources,
4142
} from '@angular/core';
4243

4344
import {BrowserDomAdapter} from './browser/browser_adapter';
@@ -125,7 +126,20 @@ export function bootstrapApplication(
125126
rootComponent: Type<unknown>,
126127
options?: ApplicationConfig,
127128
): Promise<ApplicationRef> {
128-
return internalCreateApplication({rootComponent, ...createProvidersConfig(options)});
129+
const config = {rootComponent, ...createProvidersConfig(options)};
130+
131+
// Attempt to resolve component resources before bootstrapping in JIT mode,
132+
// however don't interrupt the bootstrapping process.
133+
if ((typeof ngJitMode === 'undefined' || ngJitMode) && typeof fetch === 'function') {
134+
return resolveComponentResources(fetch)
135+
.catch((error) => {
136+
console.error(error);
137+
return Promise.resolve();
138+
})
139+
.then(() => internalCreateApplication(config));
140+
}
141+
142+
return internalCreateApplication(config);
129143
}
130144

131145
/**

0 commit comments

Comments
 (0)