From d0580d92e8a25878481806ebab2c60e538cbb8f7 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Fri, 23 Oct 2026 11:43:16 -0700 Subject: [PATCH] fix: substitute Angular 22.1 CSS custom property namespace placeholder Angular 22.1 compiles custom properties in component styles and [style.--x] bindings to `--%NS%name` / `var(--%NS%name)` and expects the renderer to replace `%NS%`. The NativeScript renderer passed the placeholder through, so: - `var(--x)` in a component never resolved against `--x` declared in app.css/app.scss. - Declaring any custom property in a component stylesheet made the NativeScript CSS parser reject `--%NS%x:` and silently drop the whole stylesheet. Strip the placeholder (Angular's default empty namespace) for emulated and unencapsulated component styles and for setStyle/removeStyle. --- .../src/tests/css-variables.spec.ts | 67 +++++++++++++++++++ .../angular/src/lib/nativescript-renderer.ts | 19 +++++- 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 apps/nativescript-demo-ng/src/tests/css-variables.spec.ts diff --git a/apps/nativescript-demo-ng/src/tests/css-variables.spec.ts b/apps/nativescript-demo-ng/src/tests/css-variables.spec.ts new file mode 100644 index 0000000..5dffb7b --- /dev/null +++ b/apps/nativescript-demo-ng/src/tests/css-variables.spec.ts @@ -0,0 +1,67 @@ +import { + Component, + ElementRef, + inject, + NO_ERRORS_SCHEMA, + Renderer2, + ViewChild, + ViewEncapsulation, +} from '@angular/core'; +import { TestBed } from '@angular/core/testing'; +import { NativeScriptCommonModule } from '@nativescript/angular'; +import { Color, Label } from '@nativescript/core'; + +// Styles are written in the namespaced form Angular >= 22.1 compiles custom properties to, +// so these specs hold regardless of the compiler version the demo app builds with. + +@Component({ + template: ``, + styles: ['.css-var-emulated { --%NS%probe-emulated: #ff0000; background-color: var(--%NS%probe-emulated); }'], + imports: [NativeScriptCommonModule], + schemas: [NO_ERRORS_SCHEMA], +}) +class EmulatedCssVarComponent { + @ViewChild('label', { static: true }) label: ElementRef