Skip to content

Commit 9a96ea0

Browse files
committed
refactor: remove hmr compatibility alias and streamline live-reload configuration across Angular and Storybook integrations
1 parent 94c2f5b commit 9a96ea0

14 files changed

Lines changed: 72 additions & 87 deletions

File tree

apps/docs-app/docs/guides/migrating-v2-to-v3.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,4 @@ Keep automated migration tooling focused on the breaking changes above:
158158
- rewrite only the legacy `@analogjs/vite-plugin-angular/setup-vitest` setup import
159159
- flag `@analogjs/trpc` as a removed package that needs a manual migration plan
160160
- flag `experimental.useAnalogCompiler`, `analogCompilationMode`, and `@analogjs/angular-compiler` as unsupported on the current v3 alpha line rather than removed outright
161-
- treat optional helpers such as `withTypedRouter`, `withRouteContext`, `withLoaderCaching`, `withDebugRoutes`, and compatibility aliases such as `hmr` as opt-in rather than mandatory rewrites
161+
- treat optional helpers such as `withTypedRouter`, `withRouteContext`, `withLoaderCaching`, `withDebugRoutes`, and `liveReload` as opt-in rather than mandatory rewrites

apps/docs-app/docs/guides/migrating.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ export default defineConfig(({ mode }) => ({
192192

193193
Angular supports HMR where in most cases components can be updated without a full page reload. In Analog, use `liveReload` to control the Angular live-reload pipeline.
194194

195-
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `liveReload` when you need custom host, port, or path settings. `hmr` is still accepted as a compatibility alias for `liveReload`.
195+
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `liveReload` when you need custom host, port, or path settings.
196196

197-
Analog requires Angular v19 or newer for `liveReload` / `hmr` to work. On Angular v17-v18, `liveReload` and its `hmr` alias are forcibly disabled at runtime with a console warning, so HMR is unavailable on those versions.
197+
Analog requires Angular v19 or newer for `liveReload` to work. On Angular v17-v18, `liveReload` is forcibly disabled at runtime with a console warning, so HMR is unavailable on those versions.
198198

199199
```ts
200200
/// <reference types="vitest" />

apps/docs-app/docs/integrations/storybook/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default config;
9393

9494
For current Analog projects, use `framework.options.liveReload` to control Analog's Angular live-reload behavior.
9595

96-
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `framework.options.liveReload` when Storybook needs custom host, port, or path settings. `framework.options.hmr` is still accepted as a compatibility alias.
96+
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `framework.options.liveReload` when Storybook needs custom host, port, or path settings.
9797

9898
Remove the existing `webpackFinal` config function if present.
9999

apps/docs-app/docs/integrations/tailwind/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ Without `prefixes`, Analog falls back to its default Tailwind usage detection fo
124124

125125
Use `liveReload` when you need to configure Analog's Angular live-reload behavior explicitly.
126126

127-
Vite's `server.hmr` option is separate. It controls the HMR websocket transport, so you can use `server.hmr` together with `liveReload` when your dev server needs custom host, port, or path settings. `hmr` is still accepted as a compatibility alias for `liveReload`.
127+
Vite's `server.hmr` option is separate. It controls the HMR websocket transport, so you can use `server.hmr` together with `liveReload` when your dev server needs custom host, port, or path settings.
128128

129-
Angular HMR requires Angular v19 or newer. On Angular v17-v18, `liveReload` and its `hmr` alias are intentionally disabled at runtime and emit a console warning, so HMR is unavailable on those versions. For broader migration guidance, see the [migration guide](/docs/guides/migrating).
129+
Angular HMR requires Angular v19 or newer. On Angular v17-v18, `liveReload` is intentionally disabled at runtime and emits a console warning, so HMR is unavailable on those versions. For broader migration guidance, see the [migration guide](/docs/guides/migrating).
130130

131131
Tailwind support does not require you to enable HMR manually. The stylesheet pipeline is handled independently from whether Angular can produce a hot component update for a given edit.
132132

packages/platform/src/lib/options.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface Options {
9898
*
9999
* When `false`, the following top-level options are ignored because they
100100
* are only forwarded to the internal Angular plugin: `jit`,
101-
* `disableTypeChecking`, `liveReload`, `hmr`, `inlineStylesExtension`,
101+
* `disableTypeChecking`, `liveReload`, `inlineStylesExtension`,
102102
* `fileReplacements`, and `include`.
103103
*
104104
* Use this to configure the embedded Angular integration itself, not as the
@@ -124,10 +124,6 @@ export interface Options {
124124
* Defaults to `true` for watch mode.
125125
*/
126126
liveReload?: boolean;
127-
/**
128-
* Compatibility alias for `liveReload`.
129-
*/
130-
hmr?: boolean;
131127
/**
132128
* Enable debug logging for specific scopes.
133129
*

packages/platform/src/lib/platform-plugin.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ export function platformPlugin(opts: Options = {}): Plugin[] {
3030

3131
const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];
3232
const viteOptions = opts?.vite === false ? undefined : opts?.vite;
33+
const {
34+
experimental: viteExperimental,
35+
hmr: _removedViteHmrOption,
36+
...forwardedViteOptions
37+
} = viteOptions ?? {};
3338
const { ...platformOptions } = {
3439
ssr: true,
3540
...opts,
@@ -56,7 +61,7 @@ export function platformPlugin(opts: Options = {}): Plugin[] {
5661

5762
const useAngularCompilationAPI =
5863
platformOptions.experimental?.useAngularCompilationAPI ??
59-
viteOptions?.experimental?.useAngularCompilationAPI;
64+
viteExperimental?.useAngularCompilationAPI;
6065
debugPlatform('experimental options resolved', {
6166
useAngularCompilationAPI: !!useAngularCompilationAPI,
6267
typedRouter: platformOptions.experimental?.typedRouter,
@@ -112,7 +117,6 @@ export function platformPlugin(opts: Options = {}): Plugin[] {
112117
),
113118
],
114119
additionalContentDirs: platformOptions.additionalContentDirs,
115-
hmr: platformOptions.hmr,
116120
liveReload: platformOptions.liveReload,
117121
inlineStylesExtension: platformOptions.inlineStylesExtension,
118122
fileReplacements: platformOptions.fileReplacements,
@@ -124,9 +128,9 @@ export function platformPlugin(opts: Options = {}): Plugin[] {
124128
platformOptions.experimental.stylePipeline.angularPlugins,
125129
}
126130
: undefined,
127-
...(viteOptions ?? {}),
131+
...forwardedViteOptions,
128132
experimental: {
129-
...(viteOptions?.experimental ?? {}),
133+
...(viteExperimental ?? {}),
130134
useAngularCompilationAPI,
131135
},
132136
}),

packages/storybook-angular/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Storybook does not automatically infer the Tailwind plugin from your app's `vite
125125

126126
Angular reload behavior is controlled with `framework.options.liveReload`.
127127

128-
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `framework.options.liveReload` when Storybook needs custom host, port, or path settings. `framework.options.hmr` is still accepted as a compatibility alias.
128+
This is separate from Vite's `server.hmr` option, which configures the HMR websocket transport. You can use `server.hmr` together with `framework.options.liveReload` when Storybook needs custom host, port, or path settings.
129129

130130
## Enabling Zoneless Change Detection
131131

packages/storybook-angular/src/lib/preset.spec.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -132,30 +132,24 @@ describe('viteFinal', () => {
132132
};
133133

134134
describe('Angular plugin options', () => {
135-
it('prefers liveReload over hmr and keeps hmr as compatibility input', async () => {
136-
const options = makeOptions({ liveReload: false, hmr: true });
135+
it('forwards liveReload without a duplicate hmr flag', async () => {
136+
const options = makeOptions({ liveReload: false });
137137

138138
await viteFinal(baseConfig, options);
139139

140-
expect(angularPluginMock).toHaveBeenCalledWith(
141-
expect.objectContaining({
142-
liveReload: false,
143-
hmr: false,
144-
}),
145-
);
140+
const [angularOptions] = angularPluginMock.mock.calls[0];
141+
expect(angularOptions.liveReload).toBe(false);
142+
expect(angularOptions).not.toHaveProperty('hmr');
146143
});
147144

148-
it('falls back to hmr when liveReload is omitted', async () => {
149-
const options = makeOptions({ hmr: true });
145+
it('defaults liveReload to false when omitted', async () => {
146+
const options = makeOptions();
150147

151148
await viteFinal(baseConfig, options);
152149

153-
expect(angularPluginMock).toHaveBeenCalledWith(
154-
expect.objectContaining({
155-
liveReload: true,
156-
hmr: true,
157-
}),
158-
);
150+
const [angularOptions] = angularPluginMock.mock.calls[0];
151+
expect(angularOptions.liveReload).toBe(false);
152+
expect(angularOptions).not.toHaveProperty('hmr');
159153
});
160154
});
161155

packages/storybook-angular/src/lib/preset.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ export const viteFinal = async (config: any, options: any): Promise<any> => {
7575

7676
// @ts-expect-error - untyped storybook presets API
7777
const framework = await options.presets.apply('framework');
78+
const { hmr: _removedHmrOption, ...frameworkOptions } =
79+
framework.options ?? {};
7880
const experimentalZoneless = await resolveExperimentalZoneless(
79-
framework.options,
81+
frameworkOptions,
8082
options?.angularBuilderOptions,
8183
);
8284
const liveReload =
83-
typeof framework.options?.liveReload !== 'undefined'
84-
? framework.options?.liveReload
85-
: typeof framework.options?.hmr !== 'undefined'
86-
? framework.options?.hmr
87-
: false;
85+
typeof frameworkOptions.liveReload !== 'undefined'
86+
? frameworkOptions.liveReload
87+
: false;
8888
return vite.mergeConfig(config, {
8989
// Add dependencies to pre-optimization
9090
optimizeDeps: {
@@ -106,18 +106,17 @@ export const viteFinal = async (config: any, options: any): Promise<any> => {
106106
plugins: [
107107
angular({
108108
jit:
109-
typeof framework.options?.jit !== 'undefined'
110-
? framework.options?.jit
109+
typeof frameworkOptions.jit !== 'undefined'
110+
? frameworkOptions.jit
111111
: true,
112112
liveReload,
113-
hmr: liveReload,
114113
tsconfig:
115-
typeof framework.options?.tsconfig !== 'undefined'
116-
? framework.options?.tsconfig
114+
typeof frameworkOptions.tsconfig !== 'undefined'
115+
? frameworkOptions.tsconfig
117116
: (options?.tsConfig ?? './.storybook/tsconfig.json'),
118117
inlineStylesExtension:
119-
typeof framework.options?.inlineStylesExtension !== 'undefined'
120-
? framework.options?.inlineStylesExtension
118+
typeof frameworkOptions.inlineStylesExtension !== 'undefined'
119+
? frameworkOptions.inlineStylesExtension
121120
: 'css',
122121
}),
123122
angularOptionsPlugin(options, {

packages/storybook-angular/src/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export type FrameworkOptions = {
1717
* HMR client transport.
1818
*/
1919
liveReload?: boolean;
20-
/**
21-
* Compatibility alias for `liveReload`.
22-
*/
23-
hmr?: boolean;
2420
inlineStylesExtension?: string;
2521
tsconfig?: string;
2622
experimentalZoneless?: boolean;

0 commit comments

Comments
 (0)