refactor(core): drop platform check in ImagePerformanceWarning (#59809)

Replaces `PLATFORM_ID` checks with `ngServerMode`.

PR Close #59809
This commit is contained in:
arturovt 2025-01-30 23:48:26 +02:00 committed by kirjs
parent c513e5dc2b
commit 35e25f690c

View file

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {IMAGE_CONFIG, ImageConfig, PLATFORM_ID} from './application/application_tokens';
import {IMAGE_CONFIG, ImageConfig} from './application/application_tokens';
import {Injectable} from './di';
import {inject} from './di/injector_compatibility';
import {formatRuntimeError, RuntimeErrorCode} from './errors';
@ -27,12 +27,11 @@ export class ImagePerformanceWarning implements OnDestroy {
private window: Window | null = null;
private observer: PerformanceObserver | null = null;
private options: ImageConfig = inject(IMAGE_CONFIG);
private readonly isBrowser = inject(PLATFORM_ID) === 'browser';
private lcpImageUrl?: string;
public start() {
if (
!this.isBrowser ||
(typeof ngServerMode !== 'undefined' && ngServerMode) ||
typeof PerformanceObserver === 'undefined' ||
(this.options?.disableImageSizeWarning && this.options?.disableImageLazyLoadWarning)
) {
@ -41,7 +40,7 @@ export class ImagePerformanceWarning implements OnDestroy {
this.observer = this.initPerformanceObserver();
const doc = getDocument();
const win = doc.defaultView;
if (typeof win !== 'undefined') {
if (win) {
this.window = win;
// Wait to avoid race conditions where LCP image triggers
// load event before it's recorded by the performance observer