Skip to content

Conversation

@danielroe
Copy link
Contributor

@danielroe danielroe commented Dec 25, 2025

🔗 Linked issue

nuxt/nuxt#32949

📚 Description

as false is now a valid type, this performs a && check rather than using optional chaining.

Summary by CodeRabbit

  • Chores

    • Improved stability by adding defensive null/undefined checks around internationalization configuration access to prevent potential runtime issues.
  • Tests

    • Updated a bundle size snapshot expectation to reflect a minor size delta.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 25, 2025

Walkthrough

This PR adds explicit null/undefined guards when accessing i18n options in two files: src/bundler.ts replaces nuxt.options.i18n?.experimental?.stripMessagesPayload with checks ensuring nuxt.options.i18n exists before accessing .experimental, and src/prepare/options.ts replaces optional chaining for i18n properties (strategy, defaultLocale) with explicit presence checks and adjusts warning-message construction accordingly. Additionally, an inline test snapshot in test/bundle.test.ts was updated (size string changed from "43.3k" to "43.4k"). No new control-flow branches or exported API changes were introduced.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: handle falsy options.i18n types' directly and clearly summarizes the main change: adding proper handling for falsy values of options.i18n instead of relying on optional chaining.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9cfd8ec and 90d2573.

📒 Files selected for processing (1)
  • test/bundle.test.ts
✅ Files skipped from review due to trivial changes (1)
  • test/bundle.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test (lts/*, ubuntu-latest)
  • GitHub Check: test (lts/*, windows-latest)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9b4529 and 9cfd8ec.

📒 Files selected for processing (2)
  • src/bundler.ts
  • src/prepare/options.ts
🧰 Additional context used
🧬 Code graph analysis (1)
src/prepare/options.ts (1)
src/utils.ts (1)
  • logger (188-188)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: test (lts/*, ubuntu-latest)
  • GitHub Check: test (lts/*, windows-latest)
  • GitHub Check: Redirect rules - nuxt-i18n-legacy
  • GitHub Check: Header rules - nuxt-i18n-legacy
  • GitHub Check: Pages changed - nuxt-i18n-legacy
🔇 Additional comments (3)
src/prepare/options.ts (2)

19-19: LGTM! Correctly guards against falsy i18n values.

The explicit && check properly handles the case when nuxt.options.i18n is false, avoiding property access on a boolean primitive.


25-26: LGTM! Fallback logic is correct.

The explicit && checks correctly handle the false case for nuxt.options.i18n, ensuring proper fallback to options.strategy and options.defaultLocale.

src/bundler.ts (1)

72-72: LGTM! Correctly guards against falsy i18n values.

The explicit check nuxt.options.i18n && nuxt.options.i18n.experimental?.stripMessagesPayload != null properly handles the case when nuxt.options.i18n is false, preventing the condition from incorrectly evaluating. The optional chaining for experimental?.stripMessagesPayload is appropriate since it's a nested property check.

Comment on lines 27 to 30
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.`,
)
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.

"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

@BobbieGoede BobbieGoede merged commit b8d1c0c into main Jan 7, 2026
11 checks passed
@BobbieGoede BobbieGoede deleted the fix/falsy-options branch January 7, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants