Skip to content

Commit 1214b4e

Browse files
committed
build: bootstrap app after theme is loaded
Usually themes are loaded as global styles which are blocking. This allows us to assume that by the time to app is bootstrapped, the theme should have loaded. Our own demo app doesn't work this way, because we're inserting the theme inside the main entrypoint, because we need to determine whether to insert an M2 or M3 theme. This prevented us from properly testing the theme loaded warning. These changes switch to bootstrapping the app after the theme has loaded.
1 parent 883466e commit 1214b4e

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/dev-app/main.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// Load `$localize` for examples using it.
1010
import '@angular/localize/init';
1111

12-
import {HttpClientModule} from '@angular/common/http';
1312
import {
1413
importProvidersFrom,
1514
provideZoneChangeDetection,
@@ -36,23 +35,28 @@ const theme = document.createElement('link');
3635
theme.href = cachedAppState.m3Enabled ? 'theme-m3.css' : 'theme.css';
3736
theme.id = 'theme-styles';
3837
theme.rel = 'stylesheet';
38+
39+
// Bootstrap the app after the theme has loaded so we can properly test the
40+
// theme loaded checks. This also avoids a flicker if it takes too long to load.
41+
theme.addEventListener('load', bootstrap, {once: true});
3942
document.head.appendChild(theme);
4043

41-
bootstrapApplication(DevApp, {
42-
providers: [
43-
importProvidersFrom(
44-
BrowserAnimationsModule.withConfig({
45-
disableAnimations: !cachedAppState.animations,
46-
}),
47-
RouterModule.forRoot(DEV_APP_ROUTES),
48-
HttpClientModule,
49-
),
50-
provideNativeDateAdapter(),
51-
{provide: OverlayContainer, useClass: FullscreenOverlayContainer},
52-
{provide: MAT_RIPPLE_GLOBAL_OPTIONS, useExisting: DevAppRippleOptions},
53-
{provide: Directionality, useClass: DevAppDirectionality},
54-
cachedAppState.zoneless
55-
? provideExperimentalZonelessChangeDetection()
56-
: provideZoneChangeDetection({eventCoalescing: true, runCoalescing: true}),
57-
],
58-
});
44+
function bootstrap(): void {
45+
bootstrapApplication(DevApp, {
46+
providers: [
47+
importProvidersFrom(
48+
BrowserAnimationsModule.withConfig({
49+
disableAnimations: !cachedAppState.animations,
50+
}),
51+
RouterModule.forRoot(DEV_APP_ROUTES),
52+
),
53+
provideNativeDateAdapter(),
54+
{provide: OverlayContainer, useClass: FullscreenOverlayContainer},
55+
{provide: MAT_RIPPLE_GLOBAL_OPTIONS, useExisting: DevAppRippleOptions},
56+
{provide: Directionality, useClass: DevAppDirectionality},
57+
cachedAppState.zoneless
58+
? provideExperimentalZonelessChangeDetection()
59+
: provideZoneChangeDetection({eventCoalescing: true, runCoalescing: true}),
60+
],
61+
});
62+
}

0 commit comments

Comments
 (0)