Title: Hydration writes every static attribute and binding again, even when the server rendered the same value · Issue #71971 · angular/angular · GitHub
Open Graph Title: Hydration writes every static attribute and binding again, even when the server rendered the same value · Issue #71971 · angular/angular
X Title: Hydration writes every static attribute and binding again, even when the server rendered the same value · Issue #71971 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description During hydration, Angular reuses the DOM nodes that the server rendered, but it still writes their values again: setupStaticAttributes() wri...
Open Graph Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description During hydration, Angular reuses the DOM nodes that the server rendered, but it still writes their v...
X Description: Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description During hydration, Angular reuses the DOM nodes that the server rendered, but it still writes their v...
Opengraph URL: https://github.com/angular/angular/issues/71971
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Hydration writes every static attribute and binding again, even when the server rendered the same value","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncore\n\n### Is this a regression?\n\nNo\n\n### Description\n\nDuring hydration, Angular reuses the DOM nodes that the server rendered, but it still writes their values again:\n\n- `setupStaticAttributes()` writes every static attribute, the static `class`, and the static `style` of each reused element.\n- On the first update after hydration, attribute, property, class, and style bindings write their values, because they have no previous value to compare with.\n\nThe values are the ones the server rendered, so the DOM ends up the same. The writes still cost time, and a `class` or `style` write makes the browser recalculate styles.\n\n#71874 stops these writes only for attributes that make the browser load a resource again: `src` on `iframe`, `embed`, `video`, and `audio`, and `data` on `object`. This issue tracks the cost of all the other writes.\n\nOn a table with 300 rows of static classes, ARIA attributes, and SVG icons, hydration makes 12,961 attribute writes, and 12,871 of them keep the same value. I measured an experimental patch that skips a static attribute, class, or style when the DOM already has its value:\n\n| Table, 300 rows | Today | Experimental patch |\n|---|---|---|\n| Attribute writes during hydration | 12,961 | 365 |\n| Hydration time | 22.3 ms | 10.0 ms (−55%) |\n| Hydration time, 4× CPU throttling | 162.0 ms | 61.6 ms (−62%) |\n| Elements restyled after hydration | 1,247 | 45 |\n\nHydration time runs from `bootstrapApplication()` to `ApplicationRef.whenStable()`, in headless Chrome 156 with the cache enabled. Each value is the median of 7 page loads. #62672 reported the same writes, and the discussion there put the visible effect down to DevTools disabling the cache. The cost measured here is main-thread time, not network.\n\nThe experimental patch isn't a proposal as it stands, because of `class` and `style`. An element can combine a static class with a binding or a directive, as in `\u003cdiv class=\"card\" [class.active]=\"isActive\">`. The server then renders `class=\"card active\"`, which differs from the static `card`, so core writes `card` and the binding adds `active` back. A comparison doesn't remove those writes, and skipping the static value altogether breaks other cases (see #71200).\n\nOn the table, `class` accounts for 3,915 of the writes. Most of the others are static `role`, `title`, `aria-*`, `width`, and `height` attributes, which don't have that problem.\n\n### Please provide a link to a minimal reproduction of the bug\n\nhttps://github.com/jsaguet/ngimg-hydration-repro\n\nThe experimental patch is the `core` variant in [`bench/patch.mjs` at commit `d6b35a8`](https://github.com/jsaguet/ngimg-hydration-repro/blob/d6b35a8/bench/patch.mjs). The measurements above are in [`results/timings.txt`](https://github.com/jsaguet/ngimg-hydration-repro/blob/d6b35a8/results/timings.txt) and [`results/dom-writes.txt`](https://github.com/jsaguet/ngimg-hydration-repro/blob/d6b35a8/results/dom-writes.txt) at the same commit. To run them, check out `d6b35a8`, then run `npm ci`, `npm run build:variants`, and `npm run bench`.\n\n### Please provide the exception or error you saw\n\nNo exception.\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```\nAngular CLI : 22.2.6\nAngular : 22.2.5\nNode.js : 26.11.1\nPackage Manager : npm 11.20.0\nChrome : 156\n```\n\n### Anything else?\n\nRelated: #52477, #52478, #71200, and #71874.\n","author":{"url":"https://github.com/jsaguet","@type":"Person","name":"jsaguet"},"datePublished":"2026-11-11T19:57:02Z","url":"https://github.com/angular/angular/issues/71971"}
| 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:3dbc58fc-8b83-909e-b5de-44fc28d3170e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9E2E:34DB8F:2BF0E2D:3AC6FF8:6B01D66E |
| html-safe-nonce | 867642ca1f0a2f8f5332b7d9b518424b7e21b60490cb328a06541362d5cfa88c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RTJFOjM0REI4RjoyQkYwRTJEOjNBQzZGRjg6NkIwMUQ2NkUiLCJ2aXNpdG9yX2lkIjoiMzYyMzI0MjE3ODAwMTc1MzcxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f70c714407fafdb7eb45c9b4a329ad51845b8c9a85fe1c8bce1d495c82c02e89 |
| hovercard-subject-tag | issue:6336173530 |
| 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/71971/issue_layout |
| twitter:image | https://opengraph.githubassets.com/634e156065606af577687a5c79a17b7bc368f8315e034edb5d4584bc2d147ab6/angular/angular/issues/71971 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/634e156065606af577687a5c79a17b7bc368f8315e034edb5d4584bc2d147ab6/angular/angular/issues/71971 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? core Is this a regression? No Description During hydration, Angular reuses the DOM nodes that the server rendered, but it still writes their v... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jsaguet |
| 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