Commit faa236c
fix(vite): dispatch template HMR to every component file sharing a templateUrl (#449)
* fix(vite): dispatch template HMR to every component file sharing a templateUrl
When two component .ts files declare the same external templateUrl,
editing that template dispatched angular:component-update for only the
last-transformed owner: resourceToComponent is single-valued, so the
last transform wins the slot and handleHotUpdate resolved one owner.
Mirror the multi-valued styleComponentOwners pattern for templates:
- declare templateComponentOwners: Map<string, Set<string>>
- prune it in transform beside the style prune
- populate it in the dep loop under TEMPLATE_REGEX
- iterate the owner set in handleHotUpdate instead of
resourceToComponent.get()
resourceToComponent stays single-valued; the same-file case already
worked via dispatchAllComponentsInFile. One event per owner is what the
client expects: every component listener filters on its own id, and
@angular/build does the same via externalTemplateToComponentsMap.
Fixes #445
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01665HouXD8imyMphWe1k7Dx
* fix(vite): resolve @ng/component templates per class; track owners by role
Two review findings on the multi-owner fan-out, both verified:
1. The @ng/component endpoint read templateUrls[0] of the FILE for
every requested class. In a multi-component file, a class whose
template is not first was served a sibling's markup — the fan-out
newly exposed loser owner files to that corruption. Resolve the
template per CLASS: the class's own templateUrl (new per-class
locator), then its inline template, then templateUrls[0] only as a
fallback for decorator shapes the locator cannot parse.
2. The owner-map population gate used TEMPLATE_REGEX, but a decorator
templateUrl is not required to end in .html — resolveResources reads
any file by decorator ROLE. A .css-named templateUrl lost its HMR
dispatch once the resourceToComponent fallback was gone. Track
template ownership in a directTemplateUrls role set, mirroring
directStyleUrls.
The intra-file fan-out design (dispatchAllComponentsInFile) is kept:
with per-class serving, sibling dispatch is a no-op again, and the
per-class-ownership redesign suggested in review would change behavior
main deliberately tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01665HouXD8imyMphWe1k7Dx
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent a6a472f commit faa236c
4 files changed
Lines changed: 503 additions & 19 deletions
File tree
- napi/angular-compiler
- test
- vite-plugin
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
260 | 261 | | |
261 | 262 | | |
262 | 263 | | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
263 | 305 | | |
264 | 306 | | |
265 | 307 | | |
| |||
0 commit comments