...
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"ngClass causes unnecessary CSS class mutation even if computed classes are unchanged","articleBody":"## I'm submitting a...\r\n\u003c!-- Check one of the following options with \"x\" -->\r\n\u003cpre>\u003ccode>\r\n[x] Bug report \u003c!-- Please search GitHub for a similar issue or PR before submitting -->\r\n\u003c/code>\u003c/pre>\r\n\r\n## Minimal reproduction of the problem with instructions\r\n\r\nhttps://stackblitz.com/edit/angular-jxxkvh?file=src%2Fapp%2Fapp.component.ts\r\n\r\nSteps to reproduce:\r\n* open DevTools \"Elements\" tab and inspect the `\u003cdiv>` with the `I'm red` content\r\n* click on the `I'm just triggering CD` button and observe that the `red` CSS class gets removed and added just after.\r\n\r\n## Current behavior\r\n\u003c!-- Describe how the issue manifests. -->\r\n\r\nCSS class is removed and added just after, even if a set of CSS classes doesn't change based on the model provided.\r\n\r\n## Expected behavior\r\n\r\nThere are no unnecessary CSS class mutations. \r\n\r\n## What is the motivation / use case for changing the behavior?\r\n\u003c!-- Describe the motivation or the concrete use case. -->\r\n\r\nCurrent behaviour causes unnecessary DOM access impacting overall performance.\r\nIt can also tip off people using mutation observers as reported in https://github.com/ng-bootstrap/ng-bootstrap/pull/2582#issuecomment-412438019\r\n\r\n## Environment\r\n\r\nAngular version: ALL\r\nBrowser: ALL\r\n\r\n## Additional info\r\n\r\nThis happens because I'm giving `ngClass` a new object on each CD. `NgClass` / differs assume that a new object might have different shape and removes classes from the old object. We should probably be smarter about it... ","author":{"url":"https://github.com/pkozlowski-opensource","@type":"Person","name":"pkozlowski-opensource"},"datePublished":"2018-08-16T12:25:40Z","url":"https://github.com/angular/angular/issues/25518"}
| 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:afd66a85-4097-cbcb-b1bc-17a3ee95a886 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9518:13372C:4E5B90:6C4E2C:6B045B1A |
| html-safe-nonce | 038796a72992fd814b0afb38d6bd9b872ee314f5a1e9252870a4d7067373b66a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTE4OjEzMzcyQzo0RTVCOTA6NkM0RTJDOjZCMDQ1QjFBIiwidmlzaXRvcl9pZCI6Ijc1OTA3MDM1NzE4NDM0MzkzODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d89d6d143167b233eff270628c9e83c2725df848ebac01b41909ed1874c20f3b |
| hovercard-subject-tag | issue:351182973 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | ///voltron/issues_fragments/issue_layout |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/25518/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7ee1243cd3fd2f2304482d1dd167c28bbc18bf839860fdb5e268f6f7327b3363/angular/angular/issues/25518 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7ee1243cd3fd2f2304482d1dd167c28bbc18bf839860fdb5e268f6f7327b3363/angular/angular/issues/25518 |
| og:image:alt | I'm submitting a... [x] Bug report Minimal reproduction of the problem with instructions https://stackblitz.com/edit/angular-jxxkvh?file=src/app/app.component.ts Steps to reproduce: open DevToo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | pkozlowski-opensource |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2d58451b4bcb73c33c67bfb6b28fb75fe6d5e279daf9b560fa4fd832f3d8c9a6 |
| 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 | 03e114520787ad27289207f153520ef97461127c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
| Skip to content | https://github.com/angular/angular/issues/25518#start-of-content |
| https://github.com/ |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F25518 |
| GitHubRepository hosting, code review, and collaboration | https://github.com/platform |
| CopilotAI coding agent for tasks, projects, and automated work | https://github.com/features/copilot |
| ActionsCI/CD and automation | https://github.com/features/actions |
| Code QualityQuality analysis, fixes, and enforcement | https://github.com/features/code-quality |
| CodespacesCloud development environments | https://github.com/features/codespaces |
| Code SecurityVulnerability detection and remediation | https://github.com/security/advanced-security/code-security |
| Secret ProtectionSecret scanning and leak prevention | https://github.com/security/advanced-security/secret-protection |
| All Features | https://github.com/features |
| Documentation | https://docs.github.com/en |
| Training | https://learn.github.com/skills |
| Certifications | https://learn.github.com/credentials |
| Build with Copilot | https://github.com/features/ai |
| Customize Copilot | https://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview |
| Integrations | https://github.com/marketplace |
| Trending repos | https://github.com/trending |
| GitHub Sponsors | https://github.com/open-source/sponsors |
| Developer articles | https://github.com/resources/articles |
| ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place. | https://github.blog/changelog/ |
| Enterprises | https://github.com/enterprise |
| Team | https://github.com/team |
| Startups | https://github.com/enterprise/startups |
| Nonprofits | https://github.com/solutions/industry/nonprofits |
| Healthcare | https://github.com/solutions/industry/healthcare |
| Financial services | https://github.com/solutions/industry/financial-services |
| Manufacturing | https://github.com/solutions/industry/manufacturing |
| Government | https://github.com/solutions/industry/government |
| See all industries | https://github.com/solutions/industry |
| Why GitHub | https://github.com/why-github |
| Customer Stories | https://github.com/customer-stories |
| Business insights | https://github.com/solutions/executive-insights |
| Trust Center | https://github.com/trust-center |
| GitHub Advanced SecurityEnterprise-grade code security | https://github.com/security/advanced-security |
| Copilot for businessEnterprise-grade AI features | https://github.com/features/copilot/copilot-business |
| Premium SupportEnterprise-grade 24/7 support | https://github.com/enterprise/premium-support |
| Documentation | https://docs.github.com/en |
| Resource center | https://github.com/resources |
| Blog | https://github.blog/ |
| Events & webinars | https://github.com/resources/events |
| Community Forum | https://github.com/orgs/community/discussions |
| Customer Stories | https://github.com/customer-stories |
| Integrations | https://github.com/marketplace |
| Customer support | https://help.github.com/ |
| Training | https://learn.github.com/skills |
| GitHub Status | https://www.githubstatus.com/ |
| About | https://github.com/about |
| Partners | https://github.com/partners |
| Changelog | https://github.blog/changelog/ |
| GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub. | https://githubuniverse.com/ |
| Pricing | https://github.com/pricing |
| Sign in | https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fangular%2Fangular%2Fissues%2F25518 |
| Sign up | https://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 |
| Reload | https://github.com/angular/angular/issues/25518 |
| Reload | https://github.com/angular/angular/issues/25518 |
| Reload | https://github.com/angular/angular/issues/25518 |
| angular | https://github.com/angular |
| angular | https://github.com/angular/angular |
| Code | https://github.com/angular/angular |
| Issues841 (841) | https://github.com/angular/angular/issues |
| Pull requests149 (149) | https://github.com/angular/angular/pulls |
| Discussions | https://github.com/angular/angular/discussions |
| Actions | https://github.com/angular/angular/actions |
| Projects | https://github.com/angular/angular/projects |
| Security and quality40 (40) | https://github.com/angular/angular/security |
| Insights | https://github.com/angular/angular/insights |
| https://github.com/angular/angular |
| New issue | https://github.com/login?return_to=https://github.com/angular/angular/issues/25518 |
| New issue | https://github.com/login?return_to=https://github.com/angular/angular/issues/25518 |
| ngClass causes unnecessary CSS class mutation even if computed classes are unchanged | https://github.com/angular/angular/issues/25518#top |
| P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P3%22 |
| area: commonIssues related to APIs in the @angular/common package | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20common%22 |
| area: performanceIssues related to performance | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20performance%22 |
| freq2: medium | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq2%3A%20medium%22 |
| state: confirmed | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22state%3A%20confirmed%22 |
| type: bug/fix | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%2Ffix%22 |
| workaround1: obvious | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22workaround1%3A%20obvious%22 |
| Backlog | https://github.com/angular/angular/milestone/82 |
| https://github.com/pkozlowski-opensource |
| pkozlowski-opensource | https://github.com/pkozlowski-opensource |
| on Aug 16, 2018 | https://github.com/angular/angular/issues/25518#issue-351182973 |
| https://stackblitz.com/edit/angular-jxxkvh?file=src%2Fapp%2Fapp.component.ts | https://stackblitz.com/edit/angular-jxxkvh?file=src%2Fapp%2Fapp.component.ts |
| ng-bootstrap/ng-bootstrap#2582 (comment) | https://github.com/ng-bootstrap/ng-bootstrap/pull/2582#issuecomment-412438019 |
| Next | https://github.com/angular/angular/issues/25518?timeline_page=1 |
| pkozlowski-opensource | https://github.com/pkozlowski-opensource |
| area: commonIssues related to APIs in the @angular/common package | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20common%22 |
| on Aug 16, 2018 | https://github.com/angular/angular/issues/25518#event-1792245141 |
| ngbot | https://github.com/apps/ngbot |
| needsTriage | https://github.com/angular/angular/milestone/83 |
| on Aug 16, 2018 | https://github.com/angular/angular/issues/25518#event-1792245223 |
| pkozlowski-opensource | https://github.com/pkozlowski-opensource |
| type: bug/fix | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%2Ffix%22 |
| area: performanceIssues related to performance | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20performance%22 |
| workaround1: obvious | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22workaround1%3A%20obvious%22 |
| freq2: medium | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq2%3A%20medium%22 |
| area: performanceIssues related to performance | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20performance%22 |
| on Aug 16, 2018 | https://github.com/angular/angular/issues/25518#event-1792245715 |
| pkozlowski-opensource | https://github.com/pkozlowski-opensource |
| on Aug 17, 2018 | https://github.com/angular/angular/issues/25518#event-1794115023 |
| fix(timepicker): avoid unnecessary CSS class mutation in the DOM | https://github.com/ng-bootstrap/ng-bootstrap/commit/47e91ba4a22f005c208ab73604290ae6306634ef |
| 47e91ba | https://github.com/ng-bootstrap/ng-bootstrap/commit/47e91ba4a22f005c208ab73604290ae6306634ef |
| matsko | https://github.com/matsko |
| severity3: broken | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22severity3%3A%20broken%22 |
| on Apr 25, 2019 | https://github.com/angular/angular/issues/25518#event-2301638757 |
| ngbot | https://github.com/apps/ngbot |
| needsTriage | https://github.com/angular/angular/milestone/83 |
| Backlog | https://github.com/angular/angular/milestone/82 |
| on Apr 25, 2019 | https://github.com/angular/angular/issues/25518#event-2301638776 |
| petebacondarwin | https://github.com/petebacondarwin |
| area: performanceIssues related to performance | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20performance%22 |
| state: confirmed | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22state%3A%20confirmed%22 |
| triage #1 | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22triage%20%231%22 |
| on May 28, 2020 | https://github.com/angular/angular/issues/25518#event-3382793266 |
| petebacondarwin | https://github.com/petebacondarwin |
| on May 28, 2020 | https://github.com/angular/angular/issues/25518#event-3382795206 |
| AndrewKushnir | https://github.com/AndrewKushnir |
| completed | https://github.com/angular/angular/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted |
| 5f21c6d | https://github.com/angular/angular/commit/5f21c6d627892dfad942b55f13861c213f9c0afb |
| on Jan 13, 2023 | https://github.com/angular/angular/issues/25518#event-8223477873 |
| AndrewKushnir | https://github.com/AndrewKushnir |
| on Jan 13, 2023 | https://github.com/angular/angular/issues/25518#event-8223478047 |
| perf(common): avoid excessive DOM mutation in NgClass (#48433) | https://github.com/angular/angular/commit/032b2bd689e24ece61e23bfe9a39a11676958b8d |
| #48433 | https://github.com/angular/angular/pull/48433 |
| https://docs.github.com/articles/closing-issues-via-commit-messages |
| 032b2bd | https://github.com/angular/angular/commit/032b2bd689e24ece61e23bfe9a39a11676958b8d |
| trekladyone | https://github.com/trekladyone |
| on Feb 1, 2023 | https://github.com/angular/angular/issues/25518#event-8415359759 |
| perf(docs-infra): remove usage of the NgClass directive (angular#48312) | https://github.com/trekladyone/angular/commit/9336d10418dd50808821bf6c81ba1a5f20b1f227 |
| angular#48312 | https://github.com/angular/angular/pull/48312 |
| 9336d10 | https://github.com/trekladyone/angular/commit/9336d10418dd50808821bf6c81ba1a5f20b1f227 |
| perf(common): avoid excessive DOM mutation in NgClass (angular#48433) | https://github.com/trekladyone/angular/commit/2935bc6bfb62477057ef6d8c76865cc0995948ae |
| angular#48433 | https://github.com/angular/angular/pull/48433 |
| 2935bc6 | https://github.com/trekladyone/angular/commit/2935bc6bfb62477057ef6d8c76865cc0995948ae |
| https://github.com/apps/angular-automatic-lock-bot |
| angular-automatic-lock-bot | https://github.com/apps/angular-automatic-lock-bot |
| on Feb 13, 2023 | https://github.com/angular/angular/issues/25518#issuecomment-1428207088 |
| automatic conversation locking policy | https://github.com/angular/angular/blob/8f24bc9443b3872fe095d9f7f77b308a361a13b4/docs/GITHUB_PROCESS.md#conversation-locking |
| angular-automatic-lock-bot | https://github.com/apps/angular-automatic-lock-bot |
| on Feb 13, 2023 | https://github.com/angular/angular/issues/25518#event-8506202627 |
| Sign up for free | https://github.com/signup?return_to=https://github.com/angular/angular/issues/25518 |
| Sign in to comment | https://github.com/login?return_to=https://github.com/angular/angular/issues/25518 |
| P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22P3%22 |
| area: commonIssues related to APIs in the @angular/common package | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20common%22 |
| area: performanceIssues related to performance | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22area%3A%20performance%22 |
| freq2: medium | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22freq2%3A%20medium%22 |
| state: confirmed | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22state%3A%20confirmed%22 |
| type: bug/fix | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%2Ffix%22 |
| workaround1: obvious | https://github.com/angular/angular/issues?q=state%3Aopen%20label%3A%22workaround1%3A%20obvious%22 |
| BacklogNo due date | https://github.com/angular/angular/milestone/82 |
|
| https://github.com |
| Terms | https://docs.github.com/site-policy/github-terms/github-terms-of-service |
| Privacy | https://docs.github.com/site-policy/privacy-policies/github-privacy-statement |
| Security | https://github.com/security |
| Status | https://www.githubstatus.com/ |
| Community | https://github.community/ |
| Docs | https://docs.github.com/ |
| Contact | https://support.github.com?tags=dotcom-footer |
.