-
-
Notifications
You must be signed in to change notification settings - Fork 517
fix: handle falsy options.i18n types
#3900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis PR adds explicit null/undefined guards when accessing i18n options in two files: Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Repository UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ 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)
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. Comment |
There was a problem hiding this 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
📒 Files selected for processing (2)
src/bundler.tssrc/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 falsyi18nvalues.The explicit
&&check properly handles the case whennuxt.options.i18nisfalse, avoiding property access on a boolean primitive.
25-26: LGTM! Fallback logic is correct.The explicit
&&checks correctly handle thefalsecase fornuxt.options.i18n, ensuring proper fallback tooptions.strategyandoptions.defaultLocale.src/bundler.ts (1)
72-72: LGTM! Correctly guards against falsyi18nvalues.The explicit check
nuxt.options.i18n && nuxt.options.i18n.experimental?.stripMessagesPayload != nullproperly handles the case whennuxt.options.i18nisfalse, preventing the condition from incorrectly evaluating. The optional chaining forexperimental?.stripMessagesPayloadis appropriate since it's a nested property check.
| 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.`, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) == null → false, 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.
| 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.`, | |
| ) |
| 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.
test/bundle.test.ts
Outdated
| "module": "69.4k", | ||
| "module (without vue-i18n)": "26.0k", | ||
| "vue-i18n": "43.3k", | ||
| "vue-i18n": "43.4k", |
There was a problem hiding this comment.
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
🔗 Linked issue
nuxt/nuxt#32949
📚 Description
as
falseis now a valid type, this performs a&&check rather than using optional chaining.Summary by CodeRabbit
Chores
Tests
✏️ Tip: You can customize this high-level summary in your review settings.