Skip to content

fix(vue-i18n-core): remove local composer when Suspense discards a pending branch - #2796

Merged
kazupon merged 1 commit into
intlify:v11from
FADL285:fix/2795-local-composer-scope-dispose
Nov 19, 2026
Merged

kazupon merged 1 commit into
intlify:v11from
FADL285:fix/2795-local-composer-scope-dispose

Conversation

@FADL285

@FADL285 FADL285 commented Nov 18, 2026

Copy link
Copy Markdown

Description

Fixes #2795 on the v11 line.

A component that calls useI18n() with a local scope is removed from __instances only in onUnmounted. When <Suspense> discards a branch whose async setup() is still pending, Vue stops the component's effect scope but drops the branch's post-render jobs, so onUnmounted never runs and the component stays in the registry, along with its DOM and listeners.

This change registers the deletion on the owning component's effect scope right after __setInstance:

instanceScope.run(() => {
  onScopeDispose(() => i18nInternal.__deleteInstance(instance))
})
  • It uses the component's own scope (instance.scope), not getCurrentScope(), so stopping a nested effectScope() created inside setup() does not remove the composer of a component that is still mounted.
  • The existing onUnmounted cleanup stays; deleting twice is a no-op.
  • instance.scope exists at runtime since Vue 3.2 but is not in Vue's published types, so the change uses a local type assertion.
  • master (v12) already handles this through onScopeDispose (fix: useI18n implementation with provide-inject fullyΒ #2357). This is the smallest equivalent for v11, which many apps still use with Vue 3.5.

Not changed: the optional __composerExtend disposer still runs only in onUnmounted, so an extension that allocates during setup could still skip its dispose on a discarded branch. Happy to move it too if you prefer.

Linked Issues

Fixes #2795. Reproduction: https://github.com/FADL285/vue-i18n-suspense-repro

Additional context

Tests added to packages/vue-i18n-core/test/issues.test.ts (#2795):

  1. Suspense discards a pending async child with a local scope: the registry returns to its starting size (fails before this change: expected 0, received 1).
  2. A nested effectScope() inside setup() is stopped: the component keeps its local translations until a normal unmount, which still cleans up.

issues.test.ts and i18n.test.ts: 104 tests pass. Prettier and git diff --check are clean.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 559dc879-570b-4878-809f-2c2cd70234ad

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix Β· Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@kazupon kazupon added the Type: Improvement Includes backwards-compatible fixes label Nov 19, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

@intlify/core

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

@intlify/core-base

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

@intlify/devtools-types

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

@intlify/message-compiler

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

petite-vue-i18n

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

@intlify/shared

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

vue-i18n

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

@intlify/vue-i18n-core

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

commit: 4072328

@kazupon

kazupon commented Nov 19, 2026

Copy link
Copy Markdown
Member

Thank you for the PR and the clear reproduction!

We checked it, and it fixes the reported case. We will merge it.

The same cause leaves a few more cases, so we will fix them in a follow-up PR:

  • useI18n() called after a top-level await in <script setup>: on Vue 3.5, instance.scope.run() does nothing once the scope has stopped, so the composer stays
  • the Legacy API mixin, which registers every component in beforeCreate
  • the watcher of v-t
  • the __composerExtend disposer, as you noted

Thanks!

@kazupon kazupon added Type: Bug Bug or Bug fixes and removed Type: Improvement Includes backwards-compatible fixes labels Nov 19, 2026
@kazupon
kazupon merged commit 80c4dd6 into intlify:v11 Nov 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Bug or Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants