René's URL Explorer Experiment


Title: feat(core): let applications merge the classes of an element before they are written (provideClassMerge) · Issue #72094 · angular/angular · GitHub

Open Graph Title: feat(core): let applications merge the classes of an element before they are written (provideClassMerge) · Issue #72094 · angular/angular

X Title: feat(core): let applications merge the classes of an element before they are written (provideClassMerge) · Issue #72094 · angular/angular

Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Utility CSS frameworks make two different class names conflict: px-4 from a component's host and px-2 from the template that uses it both set horiz...

Open Graph Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Utility CSS frameworks make two different class names conflict: px-4 from a component's host and px-2 from ...

X Description: Which @angular/* package(s) are relevant/related to the feature request? core Description Utility CSS frameworks make two different class names conflict: px-4 from a component's host and px-2 f...

Opengraph URL: https://github.com/angular/angular/issues/72094

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"feat(core): let applications merge the classes of an element before they are written (provideClassMerge)","articleBody":"### Which @angular/* package(s) are relevant/related to the feature request?\n\ncore\n\n### Description\n\nUtility CSS frameworks make two *different* class names conflict: `px-4` from a component's host and `px-2` from the template that uses it both set horizontal padding. Angular applies both, and the winner is decided by the order of the rules in the stylesheet, not by where the classes come from. So a consumer can't reliably override a component's classes.\n\nThis is now a mainstream setup: `ng new` offers Tailwind CSS as a stylesheet system and `ng add tailwindcss` configures it. Component libraries built on it (spartan/ui, shadcn-style libraries) all need to resolve these conflicts, usually with `tailwind-merge`.\n\nIn other frameworks this is simple because a component receives `className` / `class` as a prop and composes it itself (`cn(own, props.className)`). In Angular the classes of a host element come from sources the component can't see: the consumer's `class` and `[class]` / `[class.x]` bindings, host directives, other directives and `Renderer2`. There is no single place to merge them, so libraries work around it after Angular has written the classes. spartan/ui, for example, does it with `effect`s, a `MutationObserver` per element and suppressing CSS transitions during hydration, because the classes land in two steps and cause flicker. That's ~950 lines (with tests) and a measurable runtime cost.\n\nAngular already knows every class source of an element and their precedence, so it's the natural place to resolve conflicts once, before writing to the DOM.\n\n### Proposed solution\n\nA small, generic, opt-in hook. It isn't Tailwind specific: any function that turns a list of classes into a class string.\n\n```ts\nimport {provideClassMerge} from '@angular/core';\nimport {twMerge} from 'tailwind-merge';\n\nbootstrapApplication(App, {\n  providers: [provideClassMerge((classes) => twMerge(classes))],\n});\n```\n\nSemantics:\n\n- Angular passes the classes of an element in its precedence order, lowest first: host directives → component host → other directives (matching order) → template → `Renderer2.addClass`. Within a source: static `class` → `[class]` → `[class.x]` (in template order).\n- The merge function is called once per change and the result is written to `class` with a single write.\n- SSR and hydration (including incremental hydration) produce the same classes on the server and the client. Server-rendered classes Angular doesn't own are kept until the app is stable, so classes such as `RouterLinkActive`'s don't flicker.\n- Classes added with `Renderer2.addClass` (`RouterLinkActive`, `NgClass`) take part in the merge, and `removeClass` restores the class they replaced. Classes added outside Angular (`classList`, `animate.enter`) are kept as they are.\n- Tree-shakable: without the provider only an injection token lands in the bundle. `[style]` bindings are untouched.\n- The function must be pure and deterministic (results are cached per template location).\n\n### Prototype and numbers\n\nI have a working implementation with tests (acceptance, browser, platform-server hydration, forms), API docs and a guide section: [diff against v21.2.16](https://github.com/angular/angular/compare/v21.2.16...trs-dev-1:angular:prototype/class-merge-hook) (branch `prototype/class-merge-hook` on my fork; I'll rebase it on `main` for a PR). The existing suites pass unchanged. With a global identity merge, the only differences are class order in 8 specs that assert `className` strings.\n\nTo validate it, spartan/ui (300 components) was migrated from its userland solution to the hook. Measured on the spartan docs app (Chromium, 4x CPU throttling, median of 7 runs):\n\n| | Userland merging (today) | `provideClassMerge` |\n| --- | --- | --- |\n| Elements with different classes (~46k elements, SSR + hydrated) | – | **0** |\n| Script time, `/components/date-picker` | 1637 ms | **531 ms** |\n| Total blocking time, `/components/date-picker` | 2982 ms | **1844 ms** |\n| Transition flicker on load without suppression (98 routes) | 152 transitions | **0 caused by classes** |\n| SSR time per route | 171 ms | 172 ms |\n\nCompared to stock Angular without any merging, on a list of helm-like components: rendering is faster (one `class` write per element instead of one `classList.add` per class), and updates are on par (1k rows: render 57.3 → 49.2 ms, update 13.2 → 12.4 ms).\n\nKnown cost: each changed class binding re-merges the element, so an element with N changed bindings is merged N times in one change detection.\n\n### Alternatives considered\n\n- **Userland, after Angular writes the classes** (what libraries do today): needs effects and DOM observation on every element, writes classes twice, and causes transitions during hydration that have to be suppressed.\n- **A single `[class]` binding owned by the component** (`hostClass = computed(() => cn(base, consumerClass()))` with a `class` input): it misses classes from other directives, host directives and `Renderer2`, and takes `class` away from consumers as a normal attribute.\n- **A compiler-level solution**: the sources are only known at runtime (applied directives, `createComponent({directives})`, `Renderer2`, hydration), so a runtime hook is needed anyway.\n\nI'd be happy to open a PR if the direction looks good to the team.\n\ncc spartan/ui maintainers: @goetzrobin @ashley-hunter @MerlinMoos\n","author":{"url":"https://github.com/trs-dev-1","@type":"Person","name":"trs-dev-1"},"datePublished":"2026-11-18T21:39:49Z","url":"https://github.com/angular/angular/issues/72094"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d48ae18c-029a-6f07-46c3-3c721561bcd1
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAA6E:2270F4:101FAB8:15764F2:6B0110A9
html-safe-nonceffc0731fdcef7e5bd2d8769cf464119bf78101a1206c04d4576355ca23f72d6b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTZFOjIyNzBGNDoxMDFGQUI4OjE1NzY0RjI6NkIwMTEwQTkiLCJ2aXNpdG9yX2lkIjoiMzcyMzgyOTk2NDE4MTY3MjEwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac58aa7094531647782167c6b1c02d0e3d712f62e31002c250c9f42c6773e58467
hovercard-subject-tagissue:6477271157
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/72094/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e5f32a01a19377eacd94b05da1afc62e7b501c6c0c0737e344ea914f3b21b79f/angular/angular/issues/72094
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e5f32a01a19377eacd94b05da1afc62e7b501c6c0c0737e344ea914f3b21b79f/angular/angular/issues/72094
og:image:altWhich @angular/* package(s) are relevant/related to the feature request? core Description Utility CSS frameworks make two different class names conflict: px-4 from a component's host and px-2 from ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernametrs-dev-1
hostnamegithub.com
expected-hostnamegithub.com
Nonecb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124
turbo-cache-controlno-preview
go-importgithub.com/angular/angular git https://github.com/angular/angular.git
octolytics-dimension-user_id139426
octolytics-dimension-user_loginangular
octolytics-dimension-repository_id24195339
octolytics-dimension-repository_nwoangular/angular
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id24195339
octolytics-dimension-repository_network_root_nwoangular/angular
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/angular/angular/issues/72094#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F72094
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F72094
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=angular%2Fangular
Reloadhttps://github.com/angular/angular/issues/72094
Reloadhttps://github.com/angular/angular/issues/72094
Reloadhttps://github.com/angular/angular/issues/72094
angularhttps://github.com/angular
angularhttps://github.com/angular/angular
Codehttps://github.com/angular/angular
Issues835 (835)https://github.com/angular/angular/issues
Pull requests141 (141)https://github.com/angular/angular/pulls
Discussionshttps://github.com/angular/angular/discussions
Actionshttps://github.com/angular/angular/actions
Projectshttps://github.com/angular/angular/projects
Security and quality40 (40)https://github.com/angular/angular/security
Insightshttps://github.com/angular/angular/insights
https://github.com/angular/angular
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/72094
New issuehttps://github.com/login?return_to=https://github.com/angular/angular/issues/72094
feat(core): let applications merge the classes of an element before they are written (provideClassMerge)https://github.com/angular/angular/issues/72094#top
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
needsTriagehttps://github.com/angular/angular/milestone/83
https://github.com/trs-dev-1
trs-dev-1https://github.com/trs-dev-1
on Nov 18, 2026https://github.com/angular/angular/issues/72094#issue-6477271157
diff against v21.2.16https://github.com/angular/angular/compare/v21.2.16...trs-dev-1:angular:prototype/class-merge-hook
@goetzrobinhttps://github.com/goetzrobin
@ashley-hunterhttps://github.com/ashley-hunter
@MerlinMooshttps://github.com/MerlinMoos
angular-robothttps://github.com/apps/angular-robot
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
on Nov 18, 2026https://github.com/angular/angular/issues/72094#event-36581997499
angular-robothttps://github.com/apps/angular-robot
needsTriagehttps://github.com/angular/angular/milestone/83
on Nov 18, 2026https://github.com/angular/angular/issues/72094#event-36582000533
ngbothttps://github.com/apps/ngbot
needsTriagehttps://github.com/angular/angular/milestone/83
on Nov 18, 2026https://github.com/angular/angular/issues/72094#event-36582000773
https://github.com/Flarette
Flarettehttps://github.com/Flarette
on Nov 19, 2026https://github.com/angular/angular/issues/72094#issuecomment-7008275996
#71966https://github.com/angular/angular/pull/71966
#67519https://github.com/angular/angular/issues/67519
https://github.com/trs-dev-1
trs-dev-1https://github.com/trs-dev-1
on Nov 19, 2026https://github.com/angular/angular/issues/72094#issuecomment-7008886011
#67519https://github.com/angular/angular/issues/67519
#71966https://github.com/angular/angular/pull/71966
https://github.com/Flarette
Flarettehttps://github.com/Flarette
on Nov 19, 2026https://github.com/angular/angular/issues/72094#issuecomment-7010796327
https://github.com/Flarette
Flarettehttps://github.com/Flarette
on Nov 19, 2026https://github.com/angular/angular/issues/72094#issuecomment-7010841555
https://github.com/Flarette
Flarettehttps://github.com/Flarette
on Nov 19, 2026https://github.com/angular/angular/issues/72094#issuecomment-7010981643
https://github.com/trs-dev-1
trs-dev-1https://github.com/trs-dev-1
on Nov 19, 2026https://github.com/angular/angular/issues/72094#issuecomment-7011516098
@Flarettehttps://github.com/Flarette
https://github.com/Flarette
Flarettehttps://github.com/Flarette
on Nov 19, 2026https://github.com/angular/angular/issues/72094#issuecomment-7011589669
@Flarettehttps://github.com/Flarette
https://github.com/trs-dev-1
trs-dev-1https://github.com/trs-dev-1
on Nov 19, 2026https://github.com/angular/angular/issues/72094#issuecomment-7017281155
#67519https://github.com/angular/angular/issues/67519
Sign up for freehttps://github.com/signup?return_to=https://github.com/angular/angular/issues/72094
Sign in to commenthttps://github.com/login?return_to=https://github.com/angular/angular/issues/72094
area: coreIssues related to the framework runtimehttps://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20core%22
needsTriageNo due datehttps://github.com/angular/angular/milestone/83
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.