fix(compiler): update @ng/component URL to be relative (#59620)

This change is required to resolve https://github.com/angular/angular-cli/pull/29248 and works in conjunction with https://github.com/angular/angular-cli/pull/29386. It ensures that HMR (Hot Module Replacement) functions correctly with `base href`, proxies, and other advanced development setups.

PR Close #59620
This commit is contained in:
Alan Agius
2025-01-20 07:36:54 +00:00
committed by Pawel Kozlowski
parent 95a05bb202
commit 8dcd889987
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -106,7 +106,7 @@ runInEachFileSystem(() => {
expect(jsContents).toContain(`import * as i0 from "@angular/core";`);
expect(jsContents).toContain('function Cmp_HmrLoad(t) {');
expect(jsContents).toContain(
'import(/* @vite-ignore */\nnew URL("/@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t), import.meta.url).href)',
'import(/* @vite-ignore */\nnew URL("./@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t), import.meta.url).href)',
);
expect(jsContents).toContain(
').then(m => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, [i0], ' +
@@ -173,7 +173,7 @@ runInEachFileSystem(() => {
expect(jsContents).toContain(`import * as i1 from "./dep";`);
expect(jsContents).toContain('function Cmp_HmrLoad(t) {');
expect(jsContents).toContain(
'import(/* @vite-ignore */\nnew URL("/@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t), import.meta.url).href)',
'import(/* @vite-ignore */\nnew URL("./@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t), import.meta.url).href)',
);
expect(jsContents).toContain(
').then(m => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, [i0, i1], ' +
@@ -54,7 +54,7 @@ export interface R3HmrNamespaceDependency {
*/
export function compileHmrInitializer(meta: R3HmrMetadata): o.Expression {
const id = encodeURIComponent(`${meta.filePath}@${meta.className}`);
const urlPartial = `/@ng/component?c=${id}&t=`;
const urlPartial = `./@ng/component?c=${id}&t=`;
const moduleName = 'm';
const dataName = 'd';
const timestampName = 't';