Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import type { DevServerBuilderOutput } from './output';
interface OutputFileRecord {
contents: Uint8Array;
size: number;
hash?: string;
hash: string;
updated: boolean;
servable: boolean;
type: BuildOutputFileType;
Expand Down Expand Up @@ -540,6 +540,7 @@ function analyzeResultFiles(
contents: file.contents,
servable,
size: file.contents.byteLength,
hash: file.hash,
type: file.type,
updated: false,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ export function createAngularAssetsMiddleware(
// Inject component ID for view encapsulation if requested
const componentId = new URL(req.url, 'http://localhost').searchParams.get('ngcomp');
if (componentId !== null) {
const etag = `W/"${outputFile.contents.byteLength}-${outputFile.hash}-${componentId}"`;
if (req.headers['if-none-match'] === etag) {
res.statusCode = 304;
res.end();

return;
}
// Record the component style usage for HMR updates
const usedIds = usedComponentStyles.get(pathname);
if (usedIds === undefined) {
Expand All @@ -98,6 +105,7 @@ export function createAngularAssetsMiddleware(

res.setHeader('Content-Type', 'text/css');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('ETag', etag);
res.end(encapsulatedData);
})
.catch((e) => next(e));
Expand Down
5 changes: 4 additions & 1 deletion packages/angular/build/src/tools/vite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import { lookup as lookupMimeType } from 'mrmime';
import { extname } from 'node:path';

export type AngularMemoryOutputFiles = Map<string, { contents: Uint8Array; servable: boolean }>;
export type AngularMemoryOutputFiles = Map<
string,
{ contents: Uint8Array; hash: string; servable: boolean }
>;

export function pathnameWithoutBasePath(url: string, basePath: string): string {
const parsedUrl = new URL(url, 'http://localhost');
Expand Down