Skip to content

Conversation

kazupon
Copy link
Member

@kazupon kazupon commented Jul 23, 2025

resolve #2223
resolve #2207

Summary by CodeRabbit

  • Documentation
    • Expanded the Vue I18n Composition API guide with sections on implicit useScope resolution and best practices to avoid multiple useI18n calls in a single component.
  • Bug Fixes
    • Duplicate calls to useI18n in local scope now trigger a warning instead of an error, improving developer experience.
  • Tests
    • Updated tests to check for warnings rather than errors when duplicate local useI18n calls occur.

@kazupon kazupon added the Type: Improvement Includes backwards-compatible fixes label Jul 23, 2025
Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

This change updates Vue I18n to replace the error thrown for duplicate local useI18n calls with a runtime warning instead. Documentation is extended to clarify implicit useScope resolution and best practices for useI18n usage. Related tests and error/warning code definitions are updated to reflect this new behavior.

Changes

File(s) Change Summary
docs/guide/advanced/composition.md Added documentation on implicit useScope resolution and guidance on avoiding multiple local useI18n calls.
packages/vue-i18n-core/src/errors.ts Removed the DUPLICATE_USE_I18N_CALLING error code and its message.
packages/vue-i18n-core/src/warnings.ts Added new warning code and message for DUPLICATE_USE_I18N_CALLING.
packages/vue-i18n-core/src/i18n.ts Changed duplicate local useI18n call handling from throwing an error to issuing a warning.
packages/vue-i18n-core/test/i18n.test.ts Updated test to expect a warning instead of an error for duplicate local useI18n calls.

Sequence Diagram(s)

sequenceDiagram
    participant Component
    participant useI18n
    participant Warnings

    Component->>useI18n: call useI18n (local scope)
    useI18n->>useI18n: check for existing Composer instance
    alt No existing instance
        useI18n-->>Component: return Composer instance
    else Existing instance found
        useI18n->>Warnings: issue DUPLICATE_USE_I18N_CALLING warning
        useI18n-->>Component: return Composer instance
    end
Loading

Estimated code review effort

2 (~15 minutes)

Possibly related PRs

  • intlify/vue-i18n#2203: Added the original error for duplicate local useI18n calls, which this PR now reverses.
  • intlify/vue-i18n#2204: Further modifications to duplicate useI18n call handling, directly related to the same logic.

Poem

A warning, not an error, now hops in with grace,
When useI18n is called twice in the same place.
The docs are much clearer, the code less severe,
No more blank screens—just a bunny’s soft cheer!
🐇✨

✨ 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.

Copy link

Deploying vue-i18n-next with  Cloudflare Pages  Cloudflare Pages

Latest commit: bd074c9
Status: ✅  Deploy successful!
Preview URL: https://a5f536ea.vue-i18n-next.pages.dev
Branch Preview URL: https://fix-multi-call-local-use-i18.vue-i18n-next.pages.dev

View logs

@kazupon
Copy link
Member Author

kazupon commented Jul 23, 2025

@coderabbitai review

Copy link

coderabbitai bot commented Jul 23, 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.

Copy link

pkg-pr-new bot commented Jul 23, 2025

Open in StackBlitz

@intlify/core

npm i https://pkg.pr.new/@intlify/core@2235

@intlify/core-base

npm i https://pkg.pr.new/@intlify/core-base@2235

@intlify/devtools-types

npm i https://pkg.pr.new/@intlify/devtools-types@2235

@intlify/message-compiler

npm i https://pkg.pr.new/@intlify/message-compiler@2235

petite-vue-i18n

npm i https://pkg.pr.new/petite-vue-i18n@2235

@intlify/shared

npm i https://pkg.pr.new/@intlify/shared@2235

vue-i18n

npm i https://pkg.pr.new/vue-i18n@2235

@intlify/vue-i18n-core

npm i https://pkg.pr.new/@intlify/vue-i18n-core@2235

commit: bd074c9

Copy link

@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: 0

🧹 Nitpick comments (1)
docs/guide/advanced/composition.md (1)

403-469: LGTM! Comprehensive documentation with minor fix needed.

Excellent documentation that clearly explains the issue with multiple useI18n calls and provides actionable guidance with good/bad examples. The warning message documentation helps developers understand what they'll encounter.

However, there's a minor formatting issue to address:

-```
-[Vue I18n warn]: Duplicate `useI18n` calling by local scope. Please don't call it on local scope, due to it does not work properly in component.
-```
+```text
+[Vue I18n warn]: Duplicate `useI18n` calling by local scope. Please don't call it on local scope, due to it does not work properly in component.
+```

This addresses the markdownlint warning about missing language specification for fenced code blocks.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 61a6688 and bd074c9.

📒 Files selected for processing (5)
  • docs/guide/advanced/composition.md (1 hunks)
  • packages/vue-i18n-core/src/errors.ts (2 hunks)
  • packages/vue-i18n-core/src/i18n.ts (1 hunks)
  • packages/vue-i18n-core/src/warnings.ts (2 hunks)
  • packages/vue-i18n-core/test/i18n.test.ts (4 hunks)
🧬 Code Graph Analysis (2)
packages/vue-i18n-core/src/i18n.ts (2)
packages/shared/src/warn.ts (1)
  • warn (1-9)
packages/vue-i18n-core/src/warnings.ts (2)
  • getWarnMessage (38-43)
  • I18nWarnCodes (4-18)
packages/vue-i18n-core/test/i18n.test.ts (2)
packages/vue-i18n-core/src/warnings.ts (2)
  • warnMessages (22-36)
  • I18nWarnCodes (4-18)
packages/vue-i18n-core/src/i18n.ts (1)
  • useI18n (697-787)
🪛 markdownlint-cli2 (0.17.2)
docs/guide/advanced/composition.md

465-465: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/vue-i18n-core/src/i18n.ts (2)
packages/shared/src/warn.ts (1)
  • warn (1-9)
packages/vue-i18n-core/src/warnings.ts (2)
  • getWarnMessage (38-43)
  • I18nWarnCodes (4-18)
packages/vue-i18n-core/test/i18n.test.ts (2)
packages/vue-i18n-core/src/warnings.ts (2)
  • warnMessages (22-36)
  • I18nWarnCodes (4-18)
packages/vue-i18n-core/src/i18n.ts (1)
  • useI18n (697-787)
🪛 markdownlint-cli2 (0.17.2)
docs/guide/advanced/composition.md

465-465: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

⏰ 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). (4)
  • GitHub Check: Build (ubuntu-latest, 18)
  • GitHub Check: Build (macos-latest, 18)
  • GitHub Check: Build (windows-latest, 18)
  • GitHub Check: release
🔇 Additional comments (7)
packages/vue-i18n-core/src/errors.ts (1)

29-29: LGTM! Correctly removes the error code for duplicate useI18n calls.

The removal of DUPLICATE_USE_I18N_CALLING error code and its message is consistent with the PR objective to change duplicate useI18n calls from throwing errors to emitting warnings. The corresponding warning code has been properly added to the warnings module.

Also applies to: 60-60

packages/vue-i18n-core/src/i18n.ts (1)

776-778: LGTM! Correctly implements the error-to-warning behavior change.

The implementation properly replaces the error throw with a warning emit for duplicate useI18n calls in local scope. The warning is appropriately guarded by development mode and local scope conditions, and uses the new warning infrastructure. This maintains backward compatibility while providing better developer guidance.

packages/vue-i18n-core/src/warnings.ts (2)

15-15: Good formatting improvement.

Adding the trailing comma maintains consistency and makes future additions cleaner.


16-17: LGTM! Well-implemented warning code and message.

The new DUPLICATE_USE_I18N_CALLING warning code (13) follows the existing numbering scheme, and the warning message is clear and actionable. It effectively communicates the issue and provides guidance to developers about avoiding multiple useI18n calls in local scope.

Also applies to: 34-35

packages/vue-i18n-core/test/i18n.test.ts (2)

38-38: LGTM! Necessary import for warning testing.

The import of I18nWarnCodes and warnMessages is required for the updated test that verifies warning behavior instead of error throwing.


627-686: LGTM! Comprehensive test update for warning behavior.

The test properly validates the new warning behavior for duplicate useI18n calls:

  1. Proper mocking: Correctly mocks the warn function and suppresses console output
  2. Realistic scenario: Creates a practical test case with multiple useI18n calls through composables
  3. Accurate verification: Checks that the exact warning message is emitted
  4. Clean structure: Well-organized test that follows best practices

The test effectively ensures the behavior change from error to warning works as intended.

docs/guide/advanced/composition.md (1)

378-401: LGTM! Clear documentation of implicit useScope behavior.

The new section effectively explains the implicit useScope resolution behavior, helping developers understand when useI18n defaults to local vs global scope. The examples clearly illustrate both scenarios and promote explicit specification for better maintainability.

@kazupon kazupon merged commit 7c9742b into v11 Jul 23, 2025
27 checks passed
@kazupon kazupon deleted the fix/multi-call-local-use-i18n branch July 23, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Includes backwards-compatible fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant