Skip to content

Commit 2a4f488

Browse files
atscottthePunderWoman
authored andcommitted
fix(core): warnings for oversized images and lazy-lcp present with bootstrapModule (angular#57060)
This commit adds the `ImagePerformanceWarning` to the common bootstrap code rather than only starting it when using `bootstrapApplication`. PR Close angular#57060
1 parent 3da0254 commit 2a4f488

File tree

14 files changed

+86
-11
lines changed

14 files changed

+86
-11
lines changed

packages/core/src/image_performance_warning.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {inject} from './di/injector_compatibility';
1212
import {formatRuntimeError, RuntimeErrorCode} from './errors';
1313
import {OnDestroy} from './interface/lifecycle_hooks';
1414
import {getDocument} from './render3/interfaces/document';
15-
import {NgZone} from './zone';
1615

1716
// A delay in milliseconds before the scan is run after onLoad, to avoid any
1817
// potential race conditions with other LCP-related functions. This delay
@@ -28,7 +27,6 @@ export class ImagePerformanceWarning implements OnDestroy {
2827
private window: Window | null = null;
2928
private observer: PerformanceObserver | null = null;
3029
private options: ImageConfig = inject(IMAGE_CONFIG);
31-
private ngZone = inject(NgZone);
3230
private lcpImageUrl?: string;
3331

3432
public start() {
@@ -48,9 +46,7 @@ export class ImagePerformanceWarning implements OnDestroy {
4846
const waitToScan = () => {
4947
setTimeout(this.scanImages.bind(this), SCAN_DELAY);
5048
};
51-
// Angular doesn't have to run change detection whenever any asynchronous tasks are invoked in
52-
// the scope of this functionality.
53-
this.ngZone.runOutsideAngular(() => {
49+
const setup = () => {
5450
// Consider the case when the application is created and destroyed multiple times.
5551
// Typically, applications are created instantly once the page is loaded, and the
5652
// `window.load` listener is always triggered. However, the `window.load` event will never
@@ -61,7 +57,14 @@ export class ImagePerformanceWarning implements OnDestroy {
6157
} else {
6258
this.window?.addEventListener('load', waitToScan, {once: true});
6359
}
64-
});
60+
};
61+
// Angular doesn't have to run change detection whenever any asynchronous tasks are invoked in
62+
// the scope of this functionality.
63+
if (typeof Zone !== 'undefined') {
64+
Zone.root.run(() => setup());
65+
} else {
66+
setup();
67+
}
6568
}
6669
}
6770

packages/core/src/platform/bootstrap.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,16 @@ export function bootstrap<M>(
117117
// If the `LOCALE_ID` provider is defined at bootstrap then we set the value for ivy
118118
const localeId = envInjector.get(LOCALE_ID, DEFAULT_LOCALE_ID);
119119
setLocaleId(localeId || DEFAULT_LOCALE_ID);
120+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
121+
const imagePerformanceService = envInjector.get(ImagePerformanceWarning);
122+
imagePerformanceService.start();
123+
}
120124

121125
if (isApplicationBootstrapConfig(config)) {
122126
const appRef = envInjector.get(ApplicationRef);
123127
if (config.rootComponent !== undefined) {
124128
appRef.bootstrap(config.rootComponent);
125129
}
126-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
127-
const imagePerformanceService = envInjector.get(ImagePerformanceWarning);
128-
imagePerformanceService.start();
129-
}
130130
return appRef;
131131
} else {
132132
moduleDoBootstrap(config.moduleRef, config.allPlatformModules);

packages/core/test/bundling/animations-standalone/bundle.golden_symbols.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,9 @@
701701
{
702702
"name": "bloomHasToken"
703703
},
704+
{
705+
"name": "bootstrap"
706+
},
704707
{
705708
"name": "buildAnimationAst"
706709
},
@@ -1118,6 +1121,9 @@
11181121
{
11191122
"name": "invokeQuery"
11201123
},
1124+
{
1125+
"name": "isApplicationBootstrapConfig"
1126+
},
11211127
{
11221128
"name": "isComponentDef"
11231129
},

packages/core/test/bundling/animations/bundle.golden_symbols.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,9 @@
755755
{
756756
"name": "bloomHasToken"
757757
},
758+
{
759+
"name": "bootstrap"
760+
},
758761
{
759762
"name": "buildAnimationAst"
760763
},
@@ -1184,6 +1187,9 @@
11841187
{
11851188
"name": "invokeQuery"
11861189
},
1190+
{
1191+
"name": "isApplicationBootstrapConfig"
1192+
},
11871193
{
11881194
"name": "isComponentDef"
11891195
},

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,9 @@
572572
{
573573
"name": "bloomHasToken"
574574
},
575+
{
576+
"name": "bootstrap"
577+
},
575578
{
576579
"name": "callHook"
577580
},
@@ -938,6 +941,9 @@
938941
{
939942
"name": "invokeHostBindingsInCreationMode"
940943
},
944+
{
945+
"name": "isApplicationBootstrapConfig"
946+
},
941947
{
942948
"name": "isComponentDef"
943949
},

packages/core/test/bundling/defer/bundle.golden_symbols.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,9 @@
647647
{
648648
"name": "bloomHasToken"
649649
},
650+
{
651+
"name": "bootstrap"
652+
},
650653
{
651654
"name": "callHook"
652655
},
@@ -1130,6 +1133,9 @@
11301133
{
11311134
"name": "init_bindings"
11321135
},
1136+
{
1137+
"name": "init_bootstrap"
1138+
},
11331139
{
11341140
"name": "init_bootstrap_app_scoped"
11351141
},
@@ -1811,6 +1817,9 @@
18111817
{
18121818
"name": "init_platform_core_providers"
18131819
},
1820+
{
1821+
"name": "init_platform_destroy_listeners"
1822+
},
18141823
{
18151824
"name": "init_platform_ref"
18161825
},
@@ -2147,6 +2156,9 @@
21472156
{
21482157
"name": "invokeTriggerCleanupFns"
21492158
},
2159+
{
2160+
"name": "isApplicationBootstrapConfig"
2161+
},
21502162
{
21512163
"name": "isComponentDef"
21522164
},

packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,9 @@
812812
{
813813
"name": "bloomHasToken"
814814
},
815+
{
816+
"name": "bootstrap"
817+
},
815818
{
816819
"name": "callHook"
817820
},
@@ -1361,6 +1364,9 @@
13611364
{
13621365
"name": "isAbstractControlOptions"
13631366
},
1367+
{
1368+
"name": "isApplicationBootstrapConfig"
1369+
},
13641370
{
13651371
"name": "isArrayLike"
13661372
},

packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,9 @@
791791
{
792792
"name": "booleanAttribute"
793793
},
794+
{
795+
"name": "bootstrap"
796+
},
794797
{
795798
"name": "callHook"
796799
},
@@ -1319,6 +1322,9 @@
13191322
{
13201323
"name": "invokeHostBindingsInCreationMode"
13211324
},
1325+
{
1326+
"name": "isApplicationBootstrapConfig"
1327+
},
13221328
{
13231329
"name": "isArrayLike"
13241330
},

packages/core/test/bundling/hello_world/bundle.golden_symbols.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@
434434
{
435435
"name": "bloomHasToken"
436436
},
437+
{
438+
"name": "bootstrap"
439+
},
437440
{
438441
"name": "callHook"
439442
},
@@ -749,6 +752,9 @@
749752
{
750753
"name": "invokeHostBindingsInCreationMode"
751754
},
755+
{
756+
"name": "isApplicationBootstrapConfig"
757+
},
752758
{
753759
"name": "isComponentDef"
754760
},

packages/core/test/bundling/hydration/bundle.golden_symbols.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@
629629
{
630630
"name": "bloomHasToken"
631631
},
632+
{
633+
"name": "bootstrap"
634+
},
632635
{
633636
"name": "calcSerializedContainerSize"
634637
},
@@ -1022,6 +1025,9 @@
10221025
{
10231026
"name": "invokeHostBindingsInCreationMode"
10241027
},
1028+
{
1029+
"name": "isApplicationBootstrapConfig"
1030+
},
10251031
{
10261032
"name": "isArrayLike"
10271033
},

0 commit comments

Comments
 (0)