Title: serve: with NG_HMR_CSTYLES=1, component stylesheets not touched by the last change revert to first-build content after a rebuild · Issue #34248 · angular/angular-cli · GitHub
Open Graph Title: serve: with NG_HMR_CSTYLES=1, component stylesheets not touched by the last change revert to first-build content after a rebuild · Issue #34248 · angular/angular-cli
X Title: serve: with NG_HMR_CSTYLES=1, component stylesheets not touched by the last change revert to first-build content after a rebuild · Issue #34248 · angular/angular-cli
Description: Command serve Is this a regression? Unknown. I have only tested 22.2.1. Description With NG_HMR_CSTYLES=1 (link-based component style hot reloading), ng serve emits component stylesheets as external /
Open Graph Description: Command serve Is this a regression? Unknown. I have only tested 22.2.1. Description With NG_HMR_CSTYLES=1 (link-based component style hot reloading), ng serve emits component stylesheets as externa...
X Description: Command serve Is this a regression? Unknown. I have only tested 22.2.1. Description With NG_HMR_CSTYLES=1 (link-based component style hot reloading), ng serve emits component stylesheets as externa...
Opengraph URL: https://github.com/angular/angular-cli/issues/34248
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"serve: with NG_HMR_CSTYLES=1, component stylesheets not touched by the last change revert to first-build content after a rebuild","articleBody":"### Command\n\nserve\n\n### Is this a regression?\n\nUnknown. I have only tested 22.2.1.\n\n### Description\n\nWith `NG_HMR_CSTYLES=1` (link-based component style hot reloading), `ng serve` emits component stylesheets as external `/\u003chash>.css?ngcomp=...` links. After a rebuild, the dev server serves fresh content only for the stylesheet(s) affected by that change. Every other component stylesheet is served with its content from the first build, dropping earlier edits that are still saved on disk.\n\nEach check below is a fresh request for the page and its `?ngcomp` links, so a freshly loaded page receives the stale content too.\n\nWithout the flag, the same edit sequence (steps c1 to c5) produces no stale stylesheet.\n\nHypothesis (unverified, from reading the code, not from debugging): in `@angular/build/src/builders/application/execute-build.js`, on every rebuild with `externalRuntimeStyles` the code runs\n\n```js\n// TODO: Only attempt rebundling of invalidated styles once incremental build results are supported.\nif (rebuildState && options.externalRuntimeStyles) {\n componentStyleBundler.invalidate(rebuildState.fileChanges.all);\n const componentResults = await componentStyleBundler.bundleAllFiles(true, true);\n bundlingIndividualResults.push(...componentResults);\n}\n```\n\nso only the invalidated sheets are re-bundled, and the sheets that are not invalidated seem to be served from their initial-build output rather than their last-built output. I have not confirmed which layer (bundler cache, result merging, or the dev server asset map) drops the later content.\n\nSide observation, no claim about impact: with the flag, the SSR HTML contains no inline `\u003cstyle>` tags for component styles (links only); without it, it contains one `\u003cstyle>` per component.\n\n### Minimal Reproduction\n\n```sh\npnpm dlx @angular/cli@22.2.1 new repro --ssr --style=scss --defaults --skip-git --package-manager=pnpm\ncd repro\nmkdir src/app/a src/app/b\n```\n\n`src/app/_p.scss`:\n\n```scss\n$color: red;\n```\n\n`src/app/a/a.ts` (and the same for `src/app/b/b.ts` with `b`/`BComponent`/`app-b`):\n\n```ts\nimport { Component } from '@angular/core';\n\n@Component({\n selector: 'app-a',\n template: '\u003cp class=\"a\">a\u003c/p>',\n styleUrl: './style.scss',\n})\nexport class AComponent {}\n```\n\n`src/app/a/style.scss` (and the same for `b` with `.b`/`BASELINE-b`):\n\n```scss\n@use '../p';\n.a { color: p.$color; }\n.BASELINE-a { order: 0; }\n```\n\n`src/app/app.html`:\n\n```html\n\u003capp-a />\n\u003capp-b />\n```\n\n`src/app/app.ts`: import `AComponent` and `BComponent` and add them to `imports`.\n\nServe with the flag:\n\n```sh\nNG_HMR_CSTYLES=1 pnpm exec ng serve --port 8094 --no-open\n```\n\nHelper that fetches the page, takes every `?ngcomp` link and prints which marker classes each sheet contains (`check.sh`):\n\n```sh\n#!/bin/zsh\nlabel=$1\nhtml=$(curl -s http://localhost:8094/)\necho \"--- $label\"\necho \"$html\" | grep -oE 'href=\"[^\"]*ngcomp[^\"]*\"' | sed -E 's/href=\"//; s/\"$//; s/&/\\&/g' | while read -r h; do\n body=$(curl -s \"http://localhost:8094/$h\")\n who=$(echo \"$body\" | grep -oE '^\\.(a|b) ' | head -1 | tr -d ' .')\n markers=$(echo \"$body\" | grep -oE '(BASELINE|MARK)-[A-Za-z0-9-]+' | tr '\\n' ' ')\n echo \"$h sheet=${who:-empty(app)} markers: $markers\"\ndone\n```\n\nEdit sequence (wait about 4 seconds after each edit for the rebuild, then run `./check.sh \u003clabel>`):\n\n```sh\n./check.sh baseline\nprintf '.MARK-P1 { order: 1; }\\n' >> src/app/_p.scss # c1: edit partial\nprintf '.MARK-P2 { order: 2; }\\n' >> src/app/_p.scss # c2: edit partial again\nprintf '.MARK-A1 { order: 1; }\\n' >> src/app/a/style.scss # c3: edit sheet A only\nprintf '.MARK-P3 { order: 3; }\\n' >> src/app/_p.scss # c4: edit partial again\nprintf '.MARK-B1 { order: 1; }\\n' >> src/app/b/style.scss # c5: edit sheet B only\nprintf '.MARK-A2 { order: 2; }\\n' >> src/app/a/style.scss # c6: edit sheet A only\n```\n\nObserved with `NG_HMR_CSTYLES=1` (markers present in each served sheet; all edits are saved on disk):\n\n| step | sheet A (`a/style.scss`) | sheet B (`b/style.scss`) |\n| --- | --- | --- |\n| baseline | BASELINE-a | BASELINE-b |\n| c1 edit `_p.scss` | P1 BASELINE-a | P1 BASELINE-b |\n| c2 edit `_p.scss` | P1 P2 BASELINE-a | P1 P2 BASELINE-b |\n| c3 edit A only | P1 P2 BASELINE-a A1 | **BASELINE-b** (lost P1, P2) |\n| c4 edit `_p.scss` | P1 P2 P3 BASELINE-a A1 | P1 P2 P3 BASELINE-b |\n| c5 edit B only | **BASELINE-a** (lost P1 P2 P3 A1) | P1 P2 P3 BASELINE-b B1 |\n| c6 edit A only | P1 P2 P3 BASELINE-a A1 A2 | **BASELINE-b** (lost P1 P2 P3 B1) |\n\n(Marker names abbreviated: `P1` is `MARK-P1`, etc. At c5 and c6 the partial still contains P1, P2 and P3 on disk.)\n\nControl: steps c1 to c5 without `NG_HMR_CSTYLES` (component styles inlined in the SSR HTML, no `ngcomp` links). Every step shows all markers present in both sheets, e.g. after c3 sheet B has `MARK-P1 MARK-P2 BASELINE-b`, after c5 sheet A has `MARK-P1 MARK-P2 MARK-P3 BASELINE-a MARK-A1` and sheet B has `MARK-P1 MARK-P2 MARK-P3 BASELINE-b MARK-B1`.\n\nExpected: after each rebuild every served component stylesheet reflects the current content of its sources (the latest successful build), not only the stylesheets touched by the latest change.\n\nActual: untouched sheets revert to their first-build content until they are touched again.\n\n### Exception or Error\n\nNo error is reported by the dev server. Its log only says `Component stylesheet(s) changed.` and `Stylesheet update sent to client(s).`.\n\n### Your Environment\n\n```\nAngular CLI : 22.2.1\nAngular : 22.2.1\nNode.js : 26.7.0\nPackage Manager : pnpm 10.30.2\nOperating System : darwin arm64\n\n@angular/build : 22.2.1\n@angular/cli : 22.2.1\n@angular/common : 22.2.1\n@angular/compiler : 22.2.1\n@angular/compiler-cli : 22.2.1\n@angular/core : 22.2.1\n@angular/platform-browser : 22.2.1\n@angular/platform-server : 22.2.1\n@angular/router : 22.2.1\n@angular/ssr : 22.2.1\nrxjs : 7.8.2\ntypescript : 6.0.3\n```\n\n### Anything else relevant?\n\nStylesheets were checked with `curl` against the dev server (a fresh request per step), not in a browser, so I have not observed the visual effect in a browser. macOS (Darwin 25.x, arm64).\n","author":{"url":"https://github.com/johnjspiteri","@type":"Person","name":"johnjspiteri"},"datePublished":"2026-10-03T12:36:06Z","url":"https://github.com/angular/angular-cli/issues/34248"}
| 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:2c740d8c-cc9b-9514-31ac-acca8199ecd2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 81F8:DB09F:32408F3:402E512:6B01DE70 |
| html-safe-nonce | b609610384983fb8d7c17cd0a7e93969079ea984e65d24bbb3027c43c3778722 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUY4OkRCMDlGOjMyNDA4RjM6NDAyRTUxMjo2QjAxREU3MCIsInZpc2l0b3JfaWQiOiI3NzM5Mzg3MTY2MzA4MDMyMTEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 21ac5d9aef8f520d4ae8f25197d1d70eaf19cc95c8def21ee3b17381ebb86fb0 |
| hovercard-subject-tag | issue:5689667348 |
| 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-cli/34248/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1e538eca80ca51dde61d0e98136239e159c4e685fc7ce015919a98af40061bfa/angular/angular-cli/issues/34248 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1e538eca80ca51dde61d0e98136239e159c4e685fc7ce015919a98af40061bfa/angular/angular-cli/issues/34248 |
| og:image:alt | Command serve Is this a regression? Unknown. I have only tested 22.2.1. Description With NG_HMR_CSTYLES=1 (link-based component style hot reloading), ng serve emits component stylesheets as externa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johnjspiteri |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| 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