Skip to content

Commit f8677f6

Browse files
committed
fix(@angular/build): always record component style usage for HMR updates
When using the development server with the application builder, external component stylesheet usage must always be record to ensure that any hot replacement actions correctly reference the relevant components. Previously, browser cached styles would return a 304 status prior to recording the usage. This resulted in the development server not knowing that the component needed a potential update in the future. (cherry picked from commit bc771ae)
1 parent 6c513cf commit f8677f6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

packages/angular/build/src/tools/vite/middlewares/assets-middleware.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,23 @@ export function createAngularAssetsMiddleware(
7878
// Inject component ID for view encapsulation if requested
7979
const componentId = new URL(req.url, 'http://localhost').searchParams.get('ngcomp');
8080
if (componentId !== null) {
81-
const etag = `W/"${outputFile.contents.byteLength}-${outputFile.hash}-${componentId}"`;
82-
if (req.headers['if-none-match'] === etag) {
83-
res.statusCode = 304;
84-
res.end();
85-
86-
return;
87-
}
8881
// Record the component style usage for HMR updates
8982
const usedIds = usedComponentStyles.get(pathname);
9083
if (usedIds === undefined) {
9184
usedComponentStyles.set(pathname, new Set([componentId]));
9285
} else {
9386
usedIds.add(componentId);
9487
}
88+
89+
// Report if there are no changes to avoid reprocessing
90+
const etag = `W/"${outputFile.contents.byteLength}-${outputFile.hash}-${componentId}"`;
91+
if (req.headers['if-none-match'] === etag) {
92+
res.statusCode = 304;
93+
res.end();
94+
95+
return;
96+
}
97+
9598
// Shim the stylesheet if a component ID is provided
9699
if (componentId.length > 0) {
97100
// Validate component ID

0 commit comments

Comments
 (0)