Skip to content

fix: validate user options without default values#3654

Merged
BobbieGoede merged 1 commit intomainfrom
fix/user-options-validation
May 29, 2025
Merged

fix: validate user options without default values#3654
BobbieGoede merged 1 commit intomainfrom
fix/user-options-validation

Conversation

@BobbieGoede
Copy link
Copy Markdown
Member

@BobbieGoede BobbieGoede commented May 29, 2025

🔗 Linked issue

📚 Description

Resolves #3653

The options warnings are not logged since the options object is already merged with the default module options. This change manually merges all user module options (inline + keyed) so that we can check if an option has been left unset or if it is purposefully set to something (not undefined). This way we can log warnings for deprecated and problematic configurations that would otherwise require a breaking change to resolve.

Summary by CodeRabbit

  • Refactor
    • Improved handling of module options by merging inline options from Nuxt layers, ensuring more accurate warnings and compatibility checks related to translation features. No changes to user-facing functionality or configuration interfaces.

@BobbieGoede BobbieGoede self-assigned this May 29, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2025

Walkthrough

The code now merges Nuxt layer inline module options into the i18n user options using the getLayerI18n utility and defu. All subsequent option checks reference this merged configuration, ensuring that warnings and behaviors consider both direct and inline options. No exported function signatures were changed.

Changes

File(s) Change Summary
src/prepare/options.ts Imports NuxtI18nOptions, defu, and getLayerI18n; merges inline module options into userOptions; updates option checks to use merged options; no changes to exported function signatures.

Assessment against linked issues

Objective Addressed Explanation
Ensure i18n options consider inline module options from Nuxt layers to prevent devtools breakage (#3653)

Poem

A hop and a skip, some options combined,
Nuxt layers and i18n, perfectly aligned.
Now warnings are wise, and configs are true,
Devtools won’t freeze, thanks to this review!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ddccc5 and 1a9e339.

📒 Files selected for processing (1)
  • src/prepare/options.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/prepare/options.ts (2)
src/utils.ts (1)
  • getLayerI18n (244-255)
src/types.ts (1)
  • NuxtI18nOptions (140-252)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Test on Node.js 18 (windows-latest)
  • GitHub Check: Test on Node.js 18 (ubuntu-latest)
  • GitHub Check: Redirect rules - nuxt-i18n
  • GitHub Check: Header rules - nuxt-i18n
  • GitHub Check: Pages changed - nuxt-i18n
🔇 Additional comments (4)
src/prepare/options.ts (4)

2-5: LGTM: Import statements support the validation fix.

The new imports are necessary for implementing the user options validation fix:

  • NuxtI18nOptions type for proper typing
  • defu for merging layer options
  • getLayerI18n for extracting i18n options from layers

31-31: LGTM: Proper validation of user-set bundle options.

The change from options.bundle.optimizeTranslationDirective to userOptions?.bundle?.optimizeTranslationDirective == null correctly implements the validation fix. The optional chaining ensures the warning only appears when the user hasn't explicitly set the option.


37-37: 🛠️ Refactor suggestion

Add defensive optional chaining for consistency.

The condition correctly uses userOptions for validation, but missing optional chaining could cause runtime errors if userOptions.experimental is undefined.

Apply this diff for defensive programming:

-  if (userOptions.experimental?.autoImportTranslationFunctions && nuxt.options.imports.autoImport === false) {
+  if (userOptions.experimental?.autoImportTranslationFunctions && nuxt.options.imports.autoImport === false) {

Wait, actually the current code already has proper optional chaining (userOptions.experimental?.autoImportTranslationFunctions). The code is correct as written.

Likely an incorrect or invalid review comment.


25-29:

Details

❌ Incorrect review comment

Verify inclusion of main module options in userOptions.

The userOptions object correctly merges inline module options from all Nuxt layers, which addresses the core issue of distinguishing user-set from default values. However, this only considers layer options.

Should the main options parameter (before default merging) also be included in userOptions? Run this script to verify how the main options are handled:


🏁 Script executed:

#!/bin/bash
# Description: Check if main options should be included in userOptions
# Expected: Find where the main options parameter originates and if it contains user-set values

echo "Searching for prepareOptions function calls to understand the options parameter..."
rg -A 10 -B 5 "prepareOptions.*options"

echo -e "\nSearching for option override applications..."
rg -A 5 -B 5 "applyOptionOverrides"

Length of output: 3628


Main options are already captured in userOptions.
The spread over nuxt.options._layers.map(getLayerI18n) includes the project layer’s module config (i.e. your main options from nuxt.config). No additional inclusion of the options parameter is necessary here.

Likely an incorrect or invalid review comment.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@BobbieGoede
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 29, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 29, 2025

npm i https://pkg.pr.new/@nuxtjs/i18n@3654

commit: 1a9e339

@BobbieGoede BobbieGoede merged commit 2f90d78 into main May 29, 2025
16 checks passed
@BobbieGoede BobbieGoede deleted the fix/user-options-validation branch May 29, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant