Skip to content

fix: bootstrap NG0210 when the runtime exposes a global PerformanceObserver - #178

Open
NathanWalker wants to merge 1 commit into
mainfrom
fix/image-config-defaults
Open

fix: bootstrap NG0210 when the runtime exposes a global PerformanceObserver#178
NathanWalker wants to merge 1 commit into
mainfrom
fix/image-config-defaults

Conversation

@NathanWalker

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

Every debug boot fails on runtimes that ship a Web Performance API (e.g. @nativescript/ios 9.1.0-alpha.20, which does g.PerformanceObserver = PerformanceObserver):

NG0210: The document object is not available in this context.
Make sure the DOCUMENT injection token is provided.
    at getDocument (deps-bundle.mjs)
    at _ImagePerformanceWarning.start (deps-bundle.mjs)

Angular starts ImagePerformanceWarning at the end of internalCreateApplication whenever ngDevMode is on, and the service only bails out early in three cases:

start() {
  if (ngServerMode || typeof PerformanceObserver === 'undefined' || (bothWarningsDisabled)) return;
  this.observer = this.initPerformanceObserver();
  const doc = getDocument();   // NG0210

The missing PerformanceObserver global is what used to keep this off our path. Once the runtime defines it, the service falls through to getDocument() — which reads a module-scoped variable set by Angular's internal setDocument(), not the DOCUMENT DI token we provide via NativeScriptDocument — and throws.

What is the new behavior?

NATIVESCRIPT_MODULE_PROVIDERS now defaults IMAGE_CONFIG to disabling both image warnings, which restores the early return. That array feeds both NativeScriptModule and createProvidersConfig, so the NgModule and standalone bootstrap paths are both covered.

Both flags are required — Angular ANDs them. The provider has to live in the app/environment injector rather than COMMON_PROVIDERS, because IMAGE_CONFIG is declared providedIn: 'root' and the root environment injector self-satisfies it from the token's own factory instead of delegating to the platform injector.

The warnings scan the DOM for oversized and lazily-loaded <img> elements, so they can never produce a meaningful result under NativeScript. Apps that want them back can still provide their own IMAGE_CONFIG — app providers are applied after the NativeScript ones.

Verified against Angular 21.2.x and 22.0.x: the guard is identical in both, and IMAGE_CONFIG is public API on @angular/common in both.

…server

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.
@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 995a7770-79f6-4b99-bdc7-dfe025b21256

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant