Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function getDefineConfig(

// `stripMessagesPayload` is enabled by default when `experimental.preload` is set to true
let stripMessagesPayload = !!options.experimental.preload
if (nuxt.options.i18n?.experimental?.stripMessagesPayload != null) {
if (nuxt.options.i18n && nuxt.options.i18n.experimental?.stripMessagesPayload != null) {
stripMessagesPayload = nuxt.options.i18n.experimental.stripMessagesPayload
}

Expand Down
8 changes: 4 additions & 4 deletions src/prepare/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ export function prepareOptions({ options }: I18nNuxtContext, nuxt: Nuxt) {
)
}

if (nuxt.options.i18n?.autoDeclare && nuxt.options.imports.autoImport === false) {
if (nuxt.options.i18n && nuxt.options.i18n.autoDeclare && nuxt.options.imports.autoImport === false) {
logger.warn(
'Disabling `autoImports` in Nuxt is not compatible with `autoDeclare`, either enable `autoImports` or disable `autoDeclare`.',
)
}

const strategy = nuxt.options.i18n?.strategy || options.strategy
const defaultLocale = nuxt.options.i18n?.defaultLocale || options.defaultLocale
const strategy = (nuxt.options.i18n && nuxt.options.i18n.strategy) || options.strategy
const defaultLocale = (nuxt.options.i18n && nuxt.options.i18n.defaultLocale) || options.defaultLocale
if (strategy.endsWith('_default') && !defaultLocale) {
logger.warn(
`The \`${strategy}\` i18n strategy${nuxt.options.i18n?.strategy == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
`The \`${strategy}\` i18n strategy${(nuxt.options.i18n && nuxt.options.i18n.strategy) == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
)
Comment on lines 27 to 30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Potential logic inconsistency in warning message.

When nuxt.options.i18n is false, line 25 correctly falls back to options.strategy (the default), but the warning message check on line 29 evaluates (false && false.strategy) == nullfalse, which means "(used by default)" won't be appended.

This is inconsistent: the strategy IS being used by default when nuxt.options.i18n is false, so the message should indicate this.

🔎 Suggested fix

Option 1 (explicit null check):

-      `The \`${strategy}\` i18n strategy${(nuxt.options.i18n && nuxt.options.i18n.strategy) == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
+      `The \`${strategy}\` i18n strategy${(!nuxt.options.i18n || nuxt.options.i18n.strategy == null) ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,

Option 2 (optional chaining is safe here since we're only checking null/undefined):

-      `The \`${strategy}\` i18n strategy${(nuxt.options.i18n && nuxt.options.i18n.strategy) == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
+      `The \`${strategy}\` i18n strategy${nuxt.options.i18n?.strategy == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,

Both options correctly handle the false case, but Option 1 aligns better with the PR's approach of avoiding optional chaining.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (strategy.endsWith('_default') && !defaultLocale) {
logger.warn(
`The \`${strategy}\` i18n strategy${nuxt.options.i18n?.strategy == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
`The \`${strategy}\` i18n strategy${(nuxt.options.i18n && nuxt.options.i18n.strategy) == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
)
if (strategy.endsWith('_default') && !defaultLocale) {
logger.warn(
`The \`${strategy}\` i18n strategy${(!nuxt.options.i18n || nuxt.options.i18n.strategy == null) ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
)
Suggested change
if (strategy.endsWith('_default') && !defaultLocale) {
logger.warn(
`The \`${strategy}\` i18n strategy${nuxt.options.i18n?.strategy == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
`The \`${strategy}\` i18n strategy${(nuxt.options.i18n && nuxt.options.i18n.strategy) == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
)
if (strategy.endsWith('_default') && !defaultLocale) {
logger.warn(
`The \`${strategy}\` i18n strategy${nuxt.options.i18n?.strategy == null ? ' (used by default)' : ''} needs \`defaultLocale\` to be set.`,
)
🤖 Prompt for AI Agents
In src/prepare/options.ts around lines 27–30, the warning message's check uses
(nuxt.options.i18n && nuxt.options.i18n.strategy) == null which treats a falsy
nuxt.options.i18n (e.g. false) as if a strategy was provided; change the
condition to explicitly check for null/undefined so the "(used by default)"
suffix is appended when the module config or its strategy is absent. Replace
that sub-expression with an explicit nullish check such as (nuxt.options.i18n ==
null || nuxt.options.i18n.strategy == null) to correctly detect the default-used
case and keep the rest of the warning intact.

}

Expand Down
2 changes: 1 addition & 1 deletion test/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
"vue-i18n (without message compiler)": roundToKilobytes(withVueI18nDropCompiler.totalBytes - base.totalBytes),
};

expect(data).toMatchInlineSnapshot(`

Check failure on line 57 in test/bundle.test.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

test/bundle.test.ts > nuxt i18n bundle size > should match snapshot

Error: Snapshot `nuxt i18n bundle size > should match snapshot 1` mismatched - Expected + Received { "module": "69.4k", "module (without vue-i18n)": "26.0k", - "vue-i18n": "43.4k", + "vue-i18n": "43.3k", "vue-i18n (without message compiler)": "26.8k", } ❯ test/bundle.test.ts:57:20

Check failure on line 57 in test/bundle.test.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

test/bundle.test.ts > nuxt i18n bundle size > should match snapshot

Error: Snapshot `nuxt i18n bundle size > should match snapshot 1` mismatched - Expected + Received { "module": "69.4k", "module (without vue-i18n)": "26.0k", - "vue-i18n": "43.4k", + "vue-i18n": "43.3k", "vue-i18n (without message compiler)": "26.8k", } ❯ test/bundle.test.ts:57:20
{
"module": "69.4k",
"module (without vue-i18n)": "26.0k",
"vue-i18n": "43.3k",
"vue-i18n": "43.4k",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test was passing before without changing the snapshot

"vue-i18n (without message compiler)": "26.8k",
}
`);
Expand Down
Loading