Skip to content

Commit 788e5c9

Browse files
alan-agius4PrajaktaB27
authored andcommitted
fix(compiler): update @ng/component URL to be relative (angular#59620)
This change is required to resolve angular/angular-cli#29248 and works in conjunction with angular/angular-cli#29386. It ensures that HMR (Hot Module Replacement) functions correctly with `base href`, proxies, and other advanced development setups. PR Close angular#59620
1 parent a07b9bb commit 788e5c9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/compiler-cli/test/ngtsc/hmr_spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ runInEachFileSystem(() => {
106106
expect(jsContents).toContain(`import * as i0 from "@angular/core";`);
107107
expect(jsContents).toContain('function Cmp_HmrLoad(t) {');
108108
expect(jsContents).toContain(
109-
'import(/* @vite-ignore */\nnew URL("/@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t), import.meta.url).href)',
109+
'import(/* @vite-ignore */\nnew URL("./@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t), import.meta.url).href)',
110110
);
111111
expect(jsContents).toContain(
112112
').then(m => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, [i0], ' +
@@ -173,7 +173,7 @@ runInEachFileSystem(() => {
173173
expect(jsContents).toContain(`import * as i1 from "./dep";`);
174174
expect(jsContents).toContain('function Cmp_HmrLoad(t) {');
175175
expect(jsContents).toContain(
176-
'import(/* @vite-ignore */\nnew URL("/@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t), import.meta.url).href)',
176+
'import(/* @vite-ignore */\nnew URL("./@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t), import.meta.url).href)',
177177
);
178178
expect(jsContents).toContain(
179179
').then(m => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, [i0, i1], ' +

packages/compiler/src/render3/r3_hmr_compiler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export interface R3HmrNamespaceDependency {
5454
*/
5555
export function compileHmrInitializer(meta: R3HmrMetadata): o.Expression {
5656
const id = encodeURIComponent(`${meta.filePath}@${meta.className}`);
57-
const urlPartial = `/@ng/component?c=${id}&t=`;
57+
const urlPartial = `./@ng/component?c=${id}&t=`;
5858
const moduleName = 'm';
5959
const dataName = 'd';
6060
const timestampName = 't';

0 commit comments

Comments
 (0)