Title: provideCssVarNamespacing() breaks styling of third-party libraries themed by global CSS variables · Issue #70064 · angular/angular · GitHub
Open Graph Title: provideCssVarNamespacing() breaks styling of third-party libraries themed by global CSS variables · Issue #70064 · angular/angular
X Title: provideCssVarNamespacing() breaks styling of third-party libraries themed by global CSS variables · Issue #70064 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? compiler Is this a regression? No Description #68846 CSS Variables namespacing, introduced in v22.1.0, rewrites custom property references inside a component's styles unconditionally...
Open Graph Description: Which @angular/* package(s) are the source of the bug? compiler Is this a regression? No Description #68846 CSS Variables namespacing, introduced in v22.1.0, rewrites custom property references ins...
X Description: Which @angular/* package(s) are the source of the bug? compiler Is this a regression? No Description #68846 CSS Variables namespacing, introduced in v22.1.0, rewrites custom property references ins...
Opengraph URL: https://github.com/angular/angular/issues/70064
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"provideCssVarNamespacing() breaks styling of third-party libraries themed by global CSS variables","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncompiler\n\n### Is this a regression?\n\nNo\n\n### Description\n\n- https://github.com/angular/angular/pull/68846\n\nCSS Variables namespacing, introduced in v22.1.0, rewrites custom property references inside a component's `styles` unconditionally, while global stylesheets are left alone by design. For a library published with partial compilation that rewrite does not happen when the library is built. It happens during the **consuming application's** build, with the consumer's namespace.\n\nAs a result, calling `provideCssVarNamespacing()` breaks any third-party library that exposes theming through custom properties defined in a global stylesheet, which is the usual way libraries do it. Angular Material ends up completely unstyled.\n\nWith `provideCssVarNamespacing()`:\n\n\u003cimg width=\"620\" alt=\"with provideCssVarNamespacing\" src=\"https://raw.githubusercontent.com/lacolaco/angular-cssvar-namespacing-library-repro/main/screenshots/namespacing-on.png\" />\n\nWithout:\n\n\u003cimg width=\"620\" alt=\"without provideCssVarNamespacing\" src=\"https://raw.githubusercontent.com/lacolaco/angular-cssvar-namespacing-library-repro/main/screenshots/namespacing-off.png\" />\n\nWith `@angular/material` and the prebuilt `azure-blue` theme, a plain `\u003cbutton matButton=\"filled\">`:\n\n| computed | with `provideCssVarNamespacing()` | without |\n| --- | --- | --- |\n| `background-color` | `rgba(0, 0, 0, 0)` | `rgb(0, 92, 187)` |\n| `color` | `rgb(0, 0, 0)` | `rgb(255, 255, 255)` |\n| `border-radius` | `0px` | `9999px` |\n\nThe theme defines its tokens in the global stylesheet and the components reference them, so the two sides end up under different names:\n\n```\n$ grep -o -- \"--mat-sys-[a-z-]*:\" node_modules/@angular/material/prebuilt-themes/azure-blue.css | sort -u | wc -l\n157\n\n$ grep -o -- \"var(--mat-\" node_modules/@angular/material/fesm2022/button.mjs | wc -l\n832\n```\n\n```js\ngetComputedStyle(document.documentElement).getPropertyValue('--mat-sys-primary') // \"#005cbb\"\ngetComputedStyle(document.documentElement).getPropertyValue('--myapp_mat-sys-primary') // \"\"\n```\n\nThis is not specific to Material. A minimal library component with `color: var(--brand)` is published as\n\n```js\n// dist/ui/fesm2022/ui.mjs\nstyles: [\"#lib{color:var(--brand);border:2px solid var(--brand);...}\"]\n```\n\nand comes out of the consuming application's build as\n\n```\n#lib[_ngcontent-%COMP%]{color:var(--%NS%brand)}\n```\n\nbecause `PartialComponentLinkerVersion1.linkPartialDeclaration` re-runs `compileComponentFromMetadata`, which applies `namespaceCssVariables` to `styles` unconditionally (`packages/compiler/src/render3/view/compiler.ts`).\n\n`--global--` is the designed opt-out, but it only helps in source you control. A library would have to spell every one of its tokens `--global--…` to defend itself against a decision its consumers make, and libraries published before v22.1 obviously cannot. A consuming application has no way to apply the opt-out to a dependency.\n\nSteps to reproduce:\n\n1. `ng new` an application on 22.1\n2. `npm i @angular/material @angular/cdk` and add `node_modules/@angular/material/prebuilt-themes/azure-blue.css` to the `styles` array in `angular.json`\n3. put `\u003cbutton matButton=\"filled\">Filled button\u003c/button>` in the template\n4. add `provideCssVarNamespacing()` to `appConfig.providers`\n5. build and open the page\n\n### Please provide a link to a minimal reproduction of the bug\n\nhttps://github.com/lacolaco/angular-cssvar-namespacing-library-repro\n\n### Please provide the exception or error you saw\n\n```true\nNo errors. The declarations are silently dropped.\n```\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI : 22.1.2\nAngular : 22.1.0\nNode.js : 22.22.3\nPackage Manager : npm 10.9.8\nOperating System : darwin arm64\n\n┌───────────────────────────┬───────────────────┬───────────────────┐\n│ Package │ Installed Version │ Requested Version │\n├───────────────────────────┼───────────────────┼───────────────────┤\n│ @angular/build │ 22.1.2 │ ^22.1.2 │\n│ @angular/cdk │ 22.1.0 │ ^22.1.0 │\n│ @angular/cli │ 22.1.2 │ ^22.1.2 │\n│ @angular/common │ 22.1.0 │ ^22.1.0 │\n│ @angular/compiler │ 22.1.0 │ ^22.1.0 │\n│ @angular/compiler-cli │ 22.1.0 │ ^22.1.0 │\n│ @angular/core │ 22.1.0 │ ^22.1.0 │\n│ @angular/forms │ 22.1.0 │ ^22.1.0 │\n│ @angular/material │ 22.1.0 │ ^22.1.0 │\n│ @angular/platform-browser │ 22.1.0 │ ^22.1.0 │\n│ @angular/router │ 22.1.0 │ ^22.1.0 │\n│ ng-packagr │ 22.1.0 │ ^22.1.0 │\n│ rxjs │ 7.8.2 │ ~7.8.0 │\n│ typescript │ 6.0.3 │ ~6.0.2 │\n└───────────────────────────┴───────────────────┴───────────────────┘\n```\n\n### Anything else?\n\nFor context on prior art, in case this reads as already known: the closest discussion I found is #67362, where the mismatch between a `var()` reference and a declaration living in a global stylesheet was raised, and `--global--` was chosen as the answer.\n\nWhat doesn't appear in either PR is the distribution dimension. Neither discussion mentions partial compilation, the linker, or npm packages, and the single sentence about libraries in the description is about using `CssVarNamespacer` for JS references rather than a library's own `styles`. `--global--` only helps in source the author controls, which is what makes this case different from an application namespacing itself. I can't see the internal design doc linked from #67362, so this may well have been considered there.\n\nIf the answer here is that libraries need to adopt `--global--` for their tokens, then adopting this feature is gated on an ecosystem-wide source change rather than on an application-level provider. Every library published before 22.1 is incompatible with any consumer that turns the flag on, there is no version constraint or diagnostic that surfaces it, and the failure mode is styles silently not applying. That seems like a larger coordination problem than a minor release can carry. `--global-` with a single hyphen is already slated to become an error in v23, so parts of this are on a major track anyway.\n\nIt also seems worth asking whether linked library styles should be namespaced at all. The namespace is application-scoped (it defaults to `APP_ID`), so rewriting a dependency's `styles` during the consuming application's link step is a choice rather than a consequence. Leaving them alone would still give the feature what it is after, an application's own variables no longer colliding with another application's on the same page, while keeping libraries working.\n","author":{"url":"https://github.com/lacolaco","@type":"Person","name":"lacolaco"},"datePublished":"2026-08-04T05:51:28Z","url":"https://github.com/angular/angular/issues/70064"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d2234bb3-7ab8-04a6-3283-9e301202045d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 95C4:842EC:2F0AC90:3EBE328:6B01E151 |
| html-safe-nonce | d470e0323e3689af8efa44efd892a8e901a43065d39327ad62c34507e15ab10f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NUM0Ojg0MkVDOjJGMEFDOTA6M0VCRTMyODo2QjAxRTE1MSIsInZpc2l0b3JfaWQiOiI1NjYxMjYzNDM5MDkyMzc1ODkwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | ed168fdfdbb9140b5382e4b474af7fac1c225592e0c74d0c72a6ca6ac805d33b |
| hovercard-subject-tag | issue:5057200099 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/70064/issue_layout |
| twitter:image | https://opengraph.githubassets.com/65c8b1833fe426f06da6247b7e5b5c0d3d5a0a5f4b4b7dc6317fcae897efcf56/angular/angular/issues/70064 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/65c8b1833fe426f06da6247b7e5b5c0d3d5a0a5f4b4b7dc6317fcae897efcf56/angular/angular/issues/70064 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? compiler Is this a regression? No Description #68846 CSS Variables namespacing, introduced in v22.1.0, rewrites custom property references ins... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | lacolaco |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width