Skip to content

Commit d50788c

Browse files
committed
fix(@angular/build): replace deprecation of i18n.baseHref with a warning
In certain scenarios, users build applications with the same `baseHref` when using i18n, primarily for deploying localized applications across multiple domains. To address this, we are removing the deprecation of `i18n.baseHref` and will revisit potential options as part of #29111 Instead of deprecating `i18n.baseHref`, we now issue a warning when it is used with SSR, as this may lead to undefined behavior. Closes #29396 (cherry picked from commit 8535c11)
1 parent 5165265 commit d50788c

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

packages/angular/build/src/builders/application/options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export async function normalizeOptions(
174174
const i18nOptions: I18nOptions & {
175175
duplicateTranslationBehavior?: I18NTranslation;
176176
missingTranslationBehavior?: I18NTranslation;
177-
} = createI18nOptions(projectMetadata, options.localize, context.logger);
177+
} = createI18nOptions(projectMetadata, options.localize, context.logger, !!options.ssr);
178178
i18nOptions.duplicateTranslationBehavior = options.i18nDuplicateTranslation;
179179
i18nOptions.missingTranslationBehavior = options.i18nMissingTranslation;
180180
if (options.forceI18nFlatOutput) {

packages/angular/build/src/utils/i18n-options.ts

+18-12
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export function createI18nOptions(
8080
logger?: {
8181
warn(message: string): void;
8282
},
83+
ssrEnabled?: boolean,
8384
): I18nOptions {
8485
const { i18n: metadata = {} } = projectMetadata;
8586

@@ -110,12 +111,14 @@ export function createI18nOptions(
110111

111112
if (metadata.sourceLocale.baseHref !== undefined) {
112113
ensureString(metadata.sourceLocale.baseHref, 'i18n.sourceLocale.baseHref');
113-
logger?.warn(
114-
`The 'baseHref' field under 'i18n.sourceLocale' is deprecated and will be removed in future versions. ` +
115-
`Please use 'subPath' instead.\nNote: 'subPath' defines the URL segment for the locale, acting ` +
116-
`as both the HTML base HREF and the directory name for output.\nBy default, ` +
117-
`if not specified, 'subPath' uses the locale code.`,
118-
);
114+
if (ssrEnabled) {
115+
logger?.warn(
116+
`'baseHref' in 'i18n.sourceLocale' may lead to undefined behavior when used with SSR. ` +
117+
`Consider using 'subPath' instead.\n\n` +
118+
`Note: 'subPath' specifies the URL segment for the locale, serving as both the HTML base HREF ` +
119+
`and the output directory name.\nBy default, if not explicitly set, 'subPath' defaults to the locale code.`,
120+
);
121+
}
119122

120123
rawSourceLocaleBaseHref = metadata.sourceLocale.baseHref;
121124
}
@@ -156,12 +159,15 @@ export function createI18nOptions(
156159

157160
if ('baseHref' in options) {
158161
ensureString(options.baseHref, `i18n.locales.${locale}.baseHref`);
159-
logger?.warn(
160-
`The 'baseHref' field under 'i18n.locales.${locale}' is deprecated and will be removed in future versions. ` +
161-
`Please use 'subPath' instead.\nNote: 'subPath' defines the URL segment for the locale, acting ` +
162-
`as both the HTML base HREF and the directory name for output.\nBy default, ` +
163-
`if not specified, 'subPath' uses the locale code.`,
164-
);
162+
163+
if (ssrEnabled) {
164+
logger?.warn(
165+
`'baseHref' in 'i18n.locales.${locale}' may lead to undefined behavior when used with SSR. ` +
166+
`Consider using 'subPath' instead.\n\n` +
167+
`Note: 'subPath' specifies the URL segment for the locale, serving as both the HTML base HREF ` +
168+
`and the output directory name.\nBy default, if not explicitly set, 'subPath' defaults to the locale code.`,
169+
);
170+
}
165171
baseHref = options.baseHref;
166172
}
167173

packages/angular/cli/lib/config/workspace-schema.json

-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@
284284
},
285285
"baseHref": {
286286
"type": "string",
287-
"deprecated": true,
288287
"description": "Specifies the HTML base HREF for the locale. Defaults to the locale code if not provided."
289288
},
290289
"subPath": {
@@ -356,7 +355,6 @@
356355
},
357356
"baseHref": {
358357
"type": "string",
359-
"deprecated": true,
360358
"description": "Specifies the HTML base HREF for the locale. Defaults to the locale code if not provided."
361359
},
362360
"subPath": {

0 commit comments

Comments
 (0)