Skip to content

Commit 40a1db0

Browse files
committed
refactor(@angular/build): add console message to dev server when component HMR is enabled
An informational message has been added to the development server to ensure that users are aware that component HMR has been enabled and provide actionable steps in the event that an application reload may not behave as expected.
1 parent 6e416e5 commit 40a1db0

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { logging } from '@angular-devkit/core';
10+
import { executeDevServer } from '../../index';
11+
import { executeOnceAndFetch } from '../execute-fetch';
12+
import { describeServeBuilder } from '../jasmine-helpers';
13+
import { BASE_OPTIONS, DEV_SERVER_BUILDER_INFO } from '../setup';
14+
15+
describeServeBuilder(executeDevServer, DEV_SERVER_BUILDER_INFO, (harness, setupTarget) => {
16+
describe('option: "hmr"', () => {
17+
beforeEach(async () => {
18+
setupTarget(harness, {});
19+
});
20+
21+
it('shows message with opt out steps when enabled', async () => {
22+
harness.useTarget('serve', {
23+
...BASE_OPTIONS,
24+
hmr: true,
25+
});
26+
27+
const { result, logs } = await executeOnceAndFetch(harness, '/');
28+
29+
expect(result?.success).toBeTrue();
30+
expect(logs).toContain(
31+
jasmine.objectContaining<logging.LogEntry>({
32+
message: jasmine.stringMatching('Component HMR has been enabled'),
33+
}),
34+
);
35+
expect(logs).toContain(
36+
jasmine.objectContaining<logging.LogEntry>({
37+
message: jasmine.stringMatching('--no-hmr'),
38+
}),
39+
);
40+
});
41+
42+
it('does not show enabled message with opt out steps when disabled', async () => {
43+
harness.useTarget('serve', {
44+
...BASE_OPTIONS,
45+
hmr: true,
46+
});
47+
48+
const { result, logs } = await executeOnceAndFetch(harness, '/');
49+
50+
expect(result?.success).toBeTrue();
51+
expect(logs).toContain(
52+
jasmine.objectContaining<logging.LogEntry>({
53+
message: jasmine.stringMatching('Component HMR has been enabled'),
54+
}),
55+
);
56+
expect(logs).toContain(
57+
jasmine.objectContaining<logging.LogEntry>({
58+
message: jasmine.stringMatching('--no-hmr'),
59+
}),
60+
);
61+
});
62+
});
63+
});

packages/angular/build/src/builders/dev-server/vite-server.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ export async function* serveWithVite(
151151
// This will also replace file-based/inline styles as code if external runtime styles are not enabled.
152152
browserOptions.templateUpdates =
153153
serverOptions.liveReload && serverOptions.hmr && useComponentTemplateHmr;
154+
if (browserOptions.templateUpdates) {
155+
context.logger.warn(
156+
'Component HMR has been enabled.\n' +
157+
'If you encounter application reload issues, you can manually reload the page to bypass HMR and/or disable this feature with the `--no-hmr` command line option.\n' +
158+
'Please consider reporting any issues you encounter here: https://github.com/angular/angular-cli/issues\n',
159+
);
160+
}
154161

155162
browserOptions.incrementalResults = true;
156163

0 commit comments

Comments
 (0)