Skip to content

Commit 6daed00

Browse files
authored
fix: bootstrap NG0210 when the runtime exposes a global PerformanceObserver (#178)
Angular's dev-mode ImagePerformanceWarning only bails out early when PerformanceObserver is missing or both image warnings are disabled. NativeScript runtimes that ship a Web Performance API now define that global, so the service proceeds to getDocument() and throws NG0210, failing every debug boot. Default IMAGE_CONFIG to disabled for both warnings — NativeScript has no <img> elements for them to scan. Apps can still override it, since their own providers are applied after the NativeScript ones.
1 parent 780e666 commit 6daed00

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { IMAGE_CONFIG } from '@angular/common';
2+
import { TestBed } from '@angular/core/testing';
3+
import { NativeScriptModule } from '@nativescript/angular';
4+
5+
describe('IMAGE_CONFIG', () => {
6+
beforeEach(() => {
7+
return TestBed.configureTestingModule({
8+
imports: [NativeScriptModule],
9+
}).compileComponents();
10+
});
11+
12+
// Both flags are required: with either one unset, Angular reaches for `document` during
13+
// bootstrap on any runtime that exposes a global PerformanceObserver.
14+
it('disables both dev-mode image warnings', () => {
15+
const config = TestBed.inject(IMAGE_CONFIG);
16+
17+
expect(config.disableImageSizeWarning).toBe(true);
18+
expect(config.disableImageLazyLoadWarning).toBe(true);
19+
});
20+
});

packages/angular/src/lib/nativescript.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ViewportScroller, XhrFactory, ɵNullViewportScroller as NullViewportScroller } from '@angular/common';
1+
import { IMAGE_CONFIG, ViewportScroller, XhrFactory, ɵNullViewportScroller as NullViewportScroller } from '@angular/common';
22
import { ApplicationModule, ErrorHandler, Inject, NgModule, NO_ERRORS_SCHEMA, Optional, Provider, RendererFactory2, SkipSelf, StaticProvider, ɵINJECTOR_SCOPE as INJECTOR_SCOPE } from '@angular/core';
33
import { Color, Device, View } from '@nativescript/core';
44
import { AppHostView } from './app-host-view';
@@ -40,7 +40,13 @@ export const NATIVESCRIPT_MODULE_STATIC_PROVIDERS: StaticProvider[] = [
4040
{ provide: DEVICE, useValue: Device },
4141
{ provide: XhrFactory, useClass: NativescriptXhrFactory, deps: [] },
4242
];
43-
export const NATIVESCRIPT_MODULE_PROVIDERS: Provider[] = [{ provide: ViewportScroller, useClass: NullViewportScroller }];
43+
export const NATIVESCRIPT_MODULE_PROVIDERS: Provider[] = [
44+
{ provide: ViewportScroller, useClass: NullViewportScroller },
45+
// Angular's dev-mode image warnings scan the DOM for <img> elements, which
46+
// NativeScript has none of. Angular only skips them when both flags are set,
47+
// and reaches for `document` as soon as a global PerformanceObserver exists.
48+
{ provide: IMAGE_CONFIG, useValue: { disableImageSizeWarning: true, disableImageLazyLoadWarning: true } },
49+
];
4450

4551
@NgModule({
4652
imports: [ApplicationModule, DetachedLoader, NativeScriptCommonModule],

0 commit comments

Comments
 (0)