vue-i18n 11.4.21 → 11.4.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vue-i18n.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * vue-i18n v11.4.21
2
+ * vue-i18n v11.4.23
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
@@ -30,7 +30,7 @@ var Vue__namespace = /*#__PURE__*/_interopNamespaceDefault(Vue);
30
30
  *
31
31
  * @VueI18nGeneral
32
32
  */
33
- const VERSION = '11.4.21';
33
+ const VERSION = '11.4.23';
34
34
 
35
35
  const I18nErrorCodes = {
36
36
  // composer module errors
@@ -235,6 +235,34 @@ function getCurrentInstance() {
235
235
  return Vue.getCurrentInstance();
236
236
  }
237
237
  }
238
+ /**
239
+ * Get the effect scope of a component instance.
240
+ *
241
+ * Every component instance has one, but it is not in the published types of Vue.
242
+ */
243
+ function getInstanceScope(instance) {
244
+ return instance.scope;
245
+ }
246
+ /**
247
+ * Run `fn` when the effect scope of a component instance stops.
248
+ *
249
+ * Vue stops this scope when it unmounts the component, and also when
250
+ * `<Suspense>` discards a pending branch. In the second case, Vue drops the
251
+ * post-render jobs of the branch, so `onUnmounted` hooks never run.
252
+ *
253
+ * If the scope has already stopped, `fn` runs right away. This happens when
254
+ * `<Suspense>` discards a component while its async `setup()` is waiting,
255
+ * and the `setup()` continues after the `await`.
256
+ */
257
+ function onInstanceScopeDispose(instance, fn) {
258
+ const scope = getInstanceScope(instance);
259
+ if (scope.active) {
260
+ scope.run(() => Vue.onScopeDispose(fn));
261
+ }
262
+ else {
263
+ fn();
264
+ }
265
+ }
238
266
  /* eslint-enable @typescript-eslint/no-explicit-any */
239
267
 
240
268
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -1133,6 +1161,18 @@ function defineMixin(vuei18n, composer, i18n) {
1133
1161
  this.$n = (...args) => this.$i18n.n(...args);
1134
1162
  this.$tm = (key) => this.$i18n.tm(key);
1135
1163
  i18n.__setInstance(instance, this.$i18n);
1164
+ // Clean up also when the effect scope of the component stops.
1165
+ // `<Suspense>` stops the scope of a component in a discarded pending
1166
+ // branch, but drops its `unmounted` hooks (#2795).
1167
+ const vueI18n = this.$i18n;
1168
+ onInstanceScopeDispose(instance, () => {
1169
+ if (vueI18n.__disposer) {
1170
+ vueI18n.__disposer();
1171
+ delete vueI18n.__disposer;
1172
+ delete vueI18n.__extender;
1173
+ }
1174
+ i18n.__deleteInstance(instance);
1175
+ });
1136
1176
  },
1137
1177
  mounted() {
1138
1178
  },
@@ -1482,9 +1522,15 @@ function vTDirective(i18n) {
1482
1522
  const register = (el, binding) => {
1483
1523
  const [textContent, composer] = _process(binding);
1484
1524
  if (shared.inBrowser) {
1485
- el.__i18nWatcher = Vue.watch(composer.locale, () => {
1486
- binding.instance && binding.instance.$forceUpdate();
1487
- });
1525
+ // Create the watcher in the effect scope of the component, so that it
1526
+ // also stops when `<Suspense>` discards a pending branch and drops the
1527
+ // `unmounted` hook of this directive (#2795).
1528
+ const scope = getInstanceScope(binding.instance.$);
1529
+ if (scope.active) {
1530
+ el.__i18nWatcher = scope.run(() => Vue.watch(composer.locale, () => {
1531
+ binding.instance && binding.instance.$forceUpdate();
1532
+ }));
1533
+ }
1488
1534
  }
1489
1535
  el.__composer = composer;
1490
1536
  el.textContent = textContent;
@@ -1733,8 +1779,8 @@ function useI18n(options = {}) {
1733
1779
  composer[DisposeSymbol] =
1734
1780
  i18nInternal.__composerExtend(composer);
1735
1781
  }
1736
- setupLifeCycle(i18nInternal, instance, composer);
1737
1782
  i18nInternal.__setInstance(instance, composer);
1783
+ setupLifeCycle(i18nInternal, instance, composer);
1738
1784
  }
1739
1785
  return composer;
1740
1786
  }
@@ -1823,7 +1869,10 @@ function getParentComponentInstance(target, useComponent = false) {
1823
1869
  function setupLifeCycle(i18n, target, composer) {
1824
1870
  Vue.onMounted(() => {
1825
1871
  }, target);
1826
- Vue.onUnmounted(() => {
1872
+ // Clean up when the effect scope of the component stops, instead of in
1873
+ // `onUnmounted`. `<Suspense>` stops the scope of a component in a discarded
1874
+ // pending branch, but drops its `onUnmounted` hooks (#2795).
1875
+ onInstanceScopeDispose(target, () => {
1827
1876
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1828
1877
  const _composer = composer;
1829
1878
  i18n.__deleteInstance(target);
@@ -1833,7 +1882,7 @@ function setupLifeCycle(i18n, target, composer) {
1833
1882
  dispose();
1834
1883
  delete _composer[DisposeSymbol];
1835
1884
  }
1836
- }, target);
1885
+ });
1837
1886
  }
1838
1887
  const globalExportProps = [
1839
1888
  'locale',
@@ -893,6 +893,7 @@ export declare interface ComposerOptions<Schema extends {
893
893
  * - Neutralizing `<base>`, `<script>` and `<plaintext>` elements, and SVG `<animate>` and `<set>` elements
894
894
  * - Disabling javascript: URLs in href (and xlink:href of SVG), src, action, formaction, and style attributes
895
895
  * - Escaping `<` in the content of `<textarea>`, `<title>`, `<style>`, `<iframe>` and similar elements
896
+ * - Following elements as browsers do, closing those still open at the end and removing end tags that close nothing
896
897
  * - Turning a tag, a comment, or an element like `<textarea>` that is not closed at the end into text
897
898
  *
898
899
  * This is useful when translation output is used in `v-html` and the translation resource contains html markup (e.g. <b> around a user provided value).
@@ -2819,6 +2820,7 @@ export declare interface VueI18nOptions<Schema extends {
2819
2820
  * - Neutralizing `<base>`, `<script>` and `<plaintext>` elements, and SVG `<animate>` and `<set>` elements
2820
2821
  * - Disabling javascript: URLs in href (and xlink:href of SVG), src, action, formaction, and style attributes
2821
2822
  * - Escaping `<` in the content of `<textarea>`, `<title>`, `<style>`, `<iframe>` and similar elements
2823
+ * - Following elements as browsers do, closing those still open at the end and removing end tags that close nothing
2822
2824
  * - Turning a tag, a comment, or an element like `<textarea>` that is not closed at the end into text
2823
2825
  *
2824
2826
  * This is useful when translation output is used in `v-html` and the translation resource contains html markup (e.g. <b> around a user provided value).
@@ -1,10 +1,10 @@
1
1
  /*!
2
- * vue-i18n v11.4.21
2
+ * vue-i18n v11.4.23
3
3
  * (c) 2026 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
6
6
  import * as Vue from 'vue';
7
- import { getCurrentInstance as getCurrentInstance$1, createVNode, Text, computed, watch, ref, shallowRef, Fragment, defineComponent, h, getCurrentScope, onScopeDispose, effectScope, inject, onMounted, onUnmounted, isRef } from 'vue';
7
+ import { getCurrentInstance as getCurrentInstance$1, onScopeDispose, createVNode, Text, computed, watch, ref, shallowRef, Fragment, defineComponent, h, getCurrentScope, effectScope, inject, onMounted, isRef } from 'vue';
8
8
 
9
9
  /**
10
10
  * Original Utilities
@@ -321,6 +321,169 @@ function serializeAttribute(attrName, value, quote, neutralized) {
321
321
  const valueQuote = quote || '';
322
322
  return `${name}=${valueQuote}${sanitizeAttributeValue(attrName, value)}${valueQuote}`;
323
323
  }
324
+ const HTML = 0;
325
+ const SVG = 1;
326
+ const MATHML = 2;
327
+ // Elements that have no end tag, and elements that the HTML parser does not open in the body
328
+ const notOpenedElementPattern = /^(?:area|base|basefont|bgsound|br|col|embed|frame|hr|image|img|input|keygen|link|meta|param|source|track|wbr|html|head|body|frameset)$/;
329
+ // Start tags that end SVG and MathML content (and `<font>` with `color`, `face` or `size`)
330
+ const breakoutElementPattern = /^(?:b|big|blockquote|body|br|center|code|dd|div|dl|dt|em|embed|h[1-6]|head|hr|i|img|li|listing|menu|meta|nobr|ol|p|pre|ruby|s|small|span|strong|strike|sub|sup|table|tt|u|ul|var)$/;
331
+ // Start tags that close an open `<p>`, and the elements that they do not close a `<p>` through
332
+ const paragraphClosingElementPattern = /^(?:address|article|aside|blockquote|center|details|dialog|dir|div|dl|fieldset|figcaption|figure|footer|header|hgroup|main|menu|nav|ol|p|search|section|summary|ul|h[1-6]|pre|listing|form|li|dd|dt|plaintext|table|hr|xmp)$/;
333
+ const buttonScopeElementPattern = /^(?:applet|caption|html|table|td|th|marquee|object|template|button)$/;
334
+ const svgIntegrationPattern = /^(?:foreignobject|desc|title)$/;
335
+ // The names of SVG and MathML integration points (except `title`, whose content is text in HTML). Read with the
336
+ // HTML rules, they are unknown HTML elements, and their start tags become text: if the browser closed such an
337
+ // element early (for example, `<button>` of the translation closes the `<button>` that the translation is
338
+ // rendered in), its end tag would close an integration point of the page, and the rest of the page would be read
339
+ // as SVG or MathML
340
+ const integrationNamePattern = /^(?:foreignobject|desc|mi|mo|mn|ms|mtext|annotation-xml)$/;
341
+ const mathmlIntegrationPattern = /^(?:mi|mo|mn|ms|mtext)$/;
342
+ const htmlEncodingPattern = /^(?:text\/html|application\/xhtml\+xml)$/i;
343
+ function asciiLowercase(text) {
344
+ return text.replace(/[A-Z]+/g, upper => upper.toLowerCase());
345
+ }
346
+ // Whether a start tag is read with the rules of SVG and MathML content, rather than with the HTML rules
347
+ function isForeignContext(top, name) {
348
+ return (!!top &&
349
+ top.namespace !== HTML &&
350
+ (!top.integration ||
351
+ (mathmlIntegrationPattern.test(top.name) &&
352
+ (name === 'mglyph' || name === 'malignmark'))) &&
353
+ !(top.name === 'annotation-xml' && name === 'svg'));
354
+ }
355
+ function isBreakout(name, attributes) {
356
+ return (breakoutElementPattern.test(name) ||
357
+ (name === 'font' &&
358
+ (attributes.has('color') ||
359
+ attributes.has('face') ||
360
+ attributes.has('size'))));
361
+ }
362
+ // Pop the elements down to `length`, and return their end tags (innermost first).
363
+ // A `<form>` becomes text instead: in a form of the page, browsers ignore the `<form>`,
364
+ // and `</form>` would close the form of the page
365
+ function closeDownTo(stack, length, parts) {
366
+ let endTags = '';
367
+ for (let index = stack.length - 1; index >= length; index--) {
368
+ const element = stack[index];
369
+ if (element.namespace === HTML && element.name === 'form') {
370
+ parts[element.part] = escapeLessThan(parts[element.part]);
371
+ }
372
+ else {
373
+ endTags += `</${element.name}>`;
374
+ }
375
+ }
376
+ stack.length = length;
377
+ return endTags;
378
+ }
379
+ // Pop SVG and MathML elements down to an HTML element or an integration point, as the tree builder does,
380
+ // and return their end tags
381
+ function closeForeign(stack, parts) {
382
+ let length = stack.length;
383
+ while (length > 0 &&
384
+ stack[length - 1].namespace !== HTML &&
385
+ !stack[length - 1].integration) {
386
+ length--;
387
+ }
388
+ return closeDownTo(stack, length, parts);
389
+ }
390
+ /**
391
+ * Open an element for a start tag, as the tree builder does
392
+ *
393
+ * @returns The end tags to write before the start tag: the SVG and MathML elements that it ends, and a `<p>`
394
+ * of the translation that it closes, with the elements in the `<p>` (so that no formatting element in it is
395
+ * made again after it), or `undefined` when the start tag becomes text
396
+ */
397
+ function openElement(stack, parts, name, attributes, selfClosing) {
398
+ // the start tag is written after the end tags
399
+ const part = parts.length + 1;
400
+ let endTags = '';
401
+ const top = stack[stack.length - 1];
402
+ if (isForeignContext(top, name)) {
403
+ if (!isBreakout(name, attributes)) {
404
+ if (!selfClosing) {
405
+ stack.push({
406
+ name,
407
+ namespace: top.namespace,
408
+ integration: top.namespace === SVG
409
+ ? svgIntegrationPattern.test(name)
410
+ : mathmlIntegrationPattern.test(name) ||
411
+ (name === 'annotation-xml' &&
412
+ htmlEncodingPattern.test((attributes.get('encoding') || '').replace(numericCharacterReferencePattern, decodeNumericCharacterReference))),
413
+ part
414
+ });
415
+ }
416
+ return endTags;
417
+ }
418
+ endTags = closeForeign(stack, parts);
419
+ }
420
+ if (paragraphClosingElementPattern.test(name)) {
421
+ for (let index = stack.length - 1; index >= 0; index--) {
422
+ const element = stack[index];
423
+ if (element.namespace === HTML
424
+ ? buttonScopeElementPattern.test(element.name)
425
+ : element.integration) {
426
+ break;
427
+ }
428
+ if (element.namespace === HTML && element.name === 'p') {
429
+ endTags += closeDownTo(stack, index, parts);
430
+ break;
431
+ }
432
+ }
433
+ }
434
+ if (integrationNamePattern.test(name)) {
435
+ return;
436
+ }
437
+ if (name === 'svg' || name === 'math') {
438
+ if (!selfClosing) {
439
+ stack.push({
440
+ name,
441
+ namespace: name === 'svg' ? SVG : MATHML,
442
+ integration: false,
443
+ part
444
+ });
445
+ }
446
+ }
447
+ else if (!notOpenedElementPattern.test(name)) {
448
+ // HTML elements ignore `/>`
449
+ stack.push({ name, namespace: HTML, integration: false, part });
450
+ }
451
+ return endTags;
452
+ }
453
+ /**
454
+ * Close the element of an end tag: an SVG or MathML element with the same name above the innermost HTML
455
+ * element, or else an HTML element with the same name
456
+ *
457
+ * @returns The end tags to write before the end tag (of the elements in the closed element), or `undefined`
458
+ * when the end tag closes nothing in the translation, and is removed
459
+ */
460
+ function closeElement(stack, parts, name) {
461
+ let endTags = '';
462
+ if (name === 'p' || name === 'br') {
463
+ // they end SVG and MathML content
464
+ endTags = closeForeign(stack, parts);
465
+ }
466
+ let index = stack.length - 1;
467
+ while (index >= 0 &&
468
+ stack[index].namespace !== HTML &&
469
+ stack[index].name !== name) {
470
+ index--;
471
+ }
472
+ if (index >= 0 && stack[index].namespace !== HTML) ;
473
+ else {
474
+ while (index >= 0 &&
475
+ !(stack[index].namespace === HTML && stack[index].name === name)) {
476
+ index--;
477
+ }
478
+ }
479
+ if (index < 0) {
480
+ // browsers read `</br>` as `<br>`, and `</p>` without an open `<p>` as `<p></p>`
481
+ return name === 'br' || name === 'p' ? endTags : undefined;
482
+ }
483
+ endTags += closeDownTo(stack, index + 1, parts);
484
+ stack.length = index;
485
+ return endTags;
486
+ }
324
487
  /**
325
488
  * Read a tag with the rules of the HTML tokenizer.
326
489
  * A start tag is written again with its attributes sanitized, and an end tag is kept as it is
@@ -328,7 +491,8 @@ function serializeAttribute(attrName, value, quote, neutralized) {
328
491
  * @param html - The HTML
329
492
  * @param start - The index of `<`
330
493
  * @param neutralized - What has been neutralized
331
- * @returns The tag, the tag name, and the index after the tag (-1 when the tag is not closed),
494
+ * @returns The tag, the tag name, the index after the tag (-1 when the tag is not closed),
495
+ * whether the start tag is self-closing (`/>`), and the attributes of the start tag,
332
496
  * or `undefined` when `<` does not start a tag
333
497
  */
334
498
  function readTag(html, start, neutralized) {
@@ -339,6 +503,7 @@ function readTag(html, start, neutralized) {
339
503
  }
340
504
  const [, slash, tagName] = tagStart;
341
505
  let tag = tagStart[0];
506
+ const attributes = new Map();
342
507
  let step;
343
508
  tagStepPattern.lastIndex = tagStartPattern.lastIndex;
344
509
  while ((step = tagStepPattern.exec(html))) {
@@ -346,17 +511,27 @@ function readTag(html, start, neutralized) {
346
511
  if (close) {
347
512
  const end = tagStepPattern.lastIndex;
348
513
  // browsers ignore the attributes of end tags
349
- return [slash ? html.slice(start, end) : tag + raw, tagName, end];
514
+ return [
515
+ slash ? html.slice(start, end) : tag + raw,
516
+ tagName,
517
+ end,
518
+ !slash && separator.endsWith('/'),
519
+ attributes
520
+ ];
350
521
  }
351
522
  if (quote && !closingQuote) {
352
523
  break;
353
524
  }
354
525
  if (!slash) {
355
526
  const value = quote ? quotedValue : unquotedValue;
527
+ const name = asciiLowercase(attrName);
528
+ if (!attributes.has(name)) {
529
+ attributes.set(name, value || '');
530
+ }
356
531
  tag += separator + serializeAttribute(attrName, value, quote, neutralized);
357
532
  }
358
533
  }
359
- return [tag, tagName, -1];
534
+ return [tag, tagName, -1, false, attributes];
360
535
  }
361
536
  /**
362
537
  * Find the end tag of an element whose content is text, as the HTML tokenizer does:
@@ -381,57 +556,79 @@ function findTextContentEnd(html, from, tagName) {
381
556
  * where each tag and each attribute starts and ends, and every attribute of every start tag is checked.
382
557
  * What is still open at the end of the string (a tag, a comment, or an element whose content is text,
383
558
  * like `<textarea>`) becomes text: on the server (SSR), the rest of the page follows the translation,
384
- * and it would be read as a part of what is open
559
+ * and it would be read as a part of what is open.
560
+ * For the same reason, the elements are followed as the tree builder of browsers opens and closes them,
561
+ * including SVG and MathML: an end tag that closes no element of the translation is removed, the elements
562
+ * in the element that an end tag closes are closed before it, and the elements still open at the end are
563
+ * closed. A `<form>` that the translation does not close becomes text, because browsers ignore it in a form
564
+ * of the page, and `</form>` would close that form
385
565
  *
386
566
  * @param html - The translated HTML
387
567
  * @returns The sanitized HTML
388
568
  */
389
569
  function sanitizeTranslatedHtml(html) {
390
570
  const neutralized = {};
391
- let result = '';
571
+ const parts = [];
572
+ const stack = [];
392
573
  let index = 0;
393
574
  let lessThan;
394
575
  while ((lessThan = html.indexOf('<', index)) !== -1) {
395
- result += html.slice(index, lessThan);
576
+ parts.push(html.slice(index, lessThan));
396
577
  index = lessThan + 1;
397
578
  const read = readTag(html, lessThan, neutralized);
398
579
  if (read) {
399
- const [tag, tagName, end] = read;
580
+ const [tag, tagName, end, selfClosing, attributes] = read;
400
581
  if (end === -1) {
401
582
  neutralized.unclosed = true;
402
- result += escapeLessThan(html.slice(lessThan));
583
+ parts.push(escapeLessThan(html.slice(lessThan)));
403
584
  index = html.length;
404
585
  break;
405
586
  }
406
587
  index = end;
407
588
  if (tag[1] === '/') {
408
- result += tag;
589
+ const endTags = closeElement(stack, parts, asciiLowercase(tagName));
590
+ if (endTags === undefined) {
591
+ neutralized.closed = true;
592
+ }
593
+ else {
594
+ if (endTags) {
595
+ neutralized.closed = true;
596
+ }
597
+ parts.push(endTags + tag);
598
+ }
409
599
  }
410
600
  else if (dangerousElementPattern.test(tagName)) {
411
601
  // the start tag becomes text
412
602
  neutralized.element = true;
413
- result += escapeLessThan(tag);
414
- }
415
- else if (textContentElementPattern.test(tagName)) {
416
- const contentEnd = findTextContentEnd(html, end, tagName);
417
- if (contentEnd === -1) {
418
- // the start tag becomes text, and the content is read as HTML, as browsers do then
419
- neutralized.unclosed = true;
420
- result += escapeLessThan(tag);
603
+ parts.push(escapeLessThan(tag));
604
+ }
605
+ else {
606
+ let content = '';
607
+ if (textContentElementPattern.test(tagName)) {
608
+ const contentEnd = findTextContentEnd(html, end, tagName);
609
+ if (contentEnd === -1) {
610
+ // the start tag becomes text, and the content is read as HTML, as browsers do then
611
+ neutralized.unclosed = true;
612
+ parts.push(escapeLessThan(tag));
613
+ continue;
614
+ }
615
+ content = escapeLessThan(html.slice(end, contentEnd));
616
+ index = contentEnd;
617
+ }
618
+ const endTags = openElement(stack, parts, asciiLowercase(tagName), attributes, selfClosing);
619
+ if (endTags === undefined) {
620
+ neutralized.closed = true;
621
+ parts.push(escapeLessThan(tag) + content);
421
622
  }
422
623
  else {
423
- result += tag + escapeLessThan(html.slice(end, contentEnd));
424
- index = contentEnd;
624
+ parts.push(endTags, tag + content);
425
625
  }
426
626
  }
427
- else {
428
- result += tag;
429
- }
430
627
  continue;
431
628
  }
432
629
  commentPattern.lastIndex = lessThan;
433
630
  if (commentPattern.test(html)) {
434
- result += html.slice(lessThan, commentPattern.lastIndex);
631
+ parts.push(html.slice(lessThan, commentPattern.lastIndex));
435
632
  index = commentPattern.lastIndex;
436
633
  continue;
437
634
  }
@@ -439,9 +636,21 @@ function sanitizeTranslatedHtml(html) {
439
636
  neutralized.unclosed = true;
440
637
  }
441
638
  // `<!DOCTYPE`, `<![CDATA[`, `<?`, `</` without a tag name, `<` at the end and any other `<` become text
442
- result += '&lt;';
639
+ parts.push('&lt;');
640
+ }
641
+ parts.push(html.slice(index));
642
+ // close the elements that are still open
643
+ for (let open = stack.length - 1; open >= 0; open--) {
644
+ const element = stack[open];
645
+ neutralized.closed = true;
646
+ if (element.namespace === HTML && element.name === 'form') {
647
+ // the browser ignores `<form>` in a form of the page, and `</form>` would close that form
648
+ parts[element.part] = escapeLessThan(parts[element.part]);
649
+ }
650
+ else {
651
+ parts.push(`</${element.name}>`);
652
+ }
443
653
  }
444
- result += html.slice(index);
445
654
  {
446
655
  if (neutralized.eventHandler) {
447
656
  warn('Potentially dangerous event handlers detected in translation. ' +
@@ -459,8 +668,12 @@ function sanitizeTranslatedHtml(html) {
459
668
  warn('Unclosed tag, comment or element (such as <textarea>) detected in translation. ' +
460
669
  'Consider closing it in your translation messages.');
461
670
  }
671
+ if (neutralized.closed) {
672
+ warn('Unclosed or misnested elements detected in translation. ' +
673
+ 'Consider closing every element in the right order in your translation messages.');
674
+ }
462
675
  }
463
- return result;
676
+ return parts.join('');
464
677
  }
465
678
 
466
679
  /**
@@ -2837,7 +3050,7 @@ function getWarnMessage$1(code, ...args) {
2837
3050
  * Intlify core-base version
2838
3051
  * @internal
2839
3052
  */
2840
- const VERSION$1 = '11.4.21';
3053
+ const VERSION$1 = '11.4.23';
2841
3054
  const NOT_REOSLVED = -1;
2842
3055
  const DEFAULT_LOCALE = 'en-US';
2843
3056
  const MISSING_RESOLVE_VALUE = '';
@@ -3978,7 +4191,7 @@ function getMessageContextOptions(context, locale, message, options, escapeParam
3978
4191
  *
3979
4192
  * @VueI18nGeneral
3980
4193
  */
3981
- const VERSION = '11.4.21';
4194
+ const VERSION = '11.4.23';
3982
4195
  /**
3983
4196
  * This is only called development env
3984
4197
  * istanbul-ignore-next
@@ -4253,6 +4466,34 @@ function getCurrentInstance() {
4253
4466
  return getCurrentInstance$1();
4254
4467
  }
4255
4468
  }
4469
+ /**
4470
+ * Get the effect scope of a component instance.
4471
+ *
4472
+ * Every component instance has one, but it is not in the published types of Vue.
4473
+ */
4474
+ function getInstanceScope(instance) {
4475
+ return instance.scope;
4476
+ }
4477
+ /**
4478
+ * Run `fn` when the effect scope of a component instance stops.
4479
+ *
4480
+ * Vue stops this scope when it unmounts the component, and also when
4481
+ * `<Suspense>` discards a pending branch. In the second case, Vue drops the
4482
+ * post-render jobs of the branch, so `onUnmounted` hooks never run.
4483
+ *
4484
+ * If the scope has already stopped, `fn` runs right away. This happens when
4485
+ * `<Suspense>` discards a component while its async `setup()` is waiting,
4486
+ * and the `setup()` continues after the `await`.
4487
+ */
4488
+ function onInstanceScopeDispose(instance, fn) {
4489
+ const scope = getInstanceScope(instance);
4490
+ if (scope.active) {
4491
+ scope.run(() => onScopeDispose(fn));
4492
+ }
4493
+ else {
4494
+ fn();
4495
+ }
4496
+ }
4256
4497
  /* eslint-enable @typescript-eslint/no-explicit-any */
4257
4498
 
4258
4499
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -5751,6 +5992,18 @@ function defineMixin(vuei18n, composer, i18n) {
5751
5992
  this.$n = (...args) => this.$i18n.n(...args);
5752
5993
  this.$tm = (key) => this.$i18n.tm(key);
5753
5994
  i18n.__setInstance(instance, this.$i18n);
5995
+ // Clean up also when the effect scope of the component stops.
5996
+ // `<Suspense>` stops the scope of a component in a discarded pending
5997
+ // branch, but drops its `unmounted` hooks (#2795).
5998
+ const vueI18n = this.$i18n;
5999
+ onInstanceScopeDispose(instance, () => {
6000
+ if (vueI18n.__disposer) {
6001
+ vueI18n.__disposer();
6002
+ delete vueI18n.__disposer;
6003
+ delete vueI18n.__extender;
6004
+ }
6005
+ i18n.__deleteInstance(instance);
6006
+ });
5754
6007
  },
5755
6008
  mounted() {
5756
6009
  /* istanbul ignore if */
@@ -6127,9 +6380,15 @@ function vTDirective(i18n) {
6127
6380
  const register = (el, binding) => {
6128
6381
  const [textContent, composer] = _process(binding);
6129
6382
  if (inBrowser) {
6130
- el.__i18nWatcher = watch(composer.locale, () => {
6131
- binding.instance && binding.instance.$forceUpdate();
6132
- });
6383
+ // Create the watcher in the effect scope of the component, so that it
6384
+ // also stops when `<Suspense>` discards a pending branch and drops the
6385
+ // `unmounted` hook of this directive (#2795).
6386
+ const scope = getInstanceScope(binding.instance.$);
6387
+ if (scope.active) {
6388
+ el.__i18nWatcher = scope.run(() => watch(composer.locale, () => {
6389
+ binding.instance && binding.instance.$forceUpdate();
6390
+ }));
6391
+ }
6133
6392
  }
6134
6393
  el.__composer = composer;
6135
6394
  el.textContent = textContent;
@@ -6431,8 +6690,8 @@ function useI18n(options = {}) {
6431
6690
  composer[DisposeSymbol] =
6432
6691
  i18nInternal.__composerExtend(composer);
6433
6692
  }
6434
- setupLifeCycle(i18nInternal, instance, composer);
6435
6693
  i18nInternal.__setInstance(instance, composer);
6694
+ setupLifeCycle(i18nInternal, instance, composer);
6436
6695
  }
6437
6696
  else {
6438
6697
  if (scope === 'local') {
@@ -6536,7 +6795,10 @@ function setupLifeCycle(i18n, target, composer) {
6536
6795
  emitter.on('*', addTimelineEvent);
6537
6796
  }
6538
6797
  }, target);
6539
- onUnmounted(() => {
6798
+ // Clean up when the effect scope of the component stops, instead of in
6799
+ // `onUnmounted`. `<Suspense>` stops the scope of a component in a discarded
6800
+ // pending branch, but drops its `onUnmounted` hooks (#2795).
6801
+ onInstanceScopeDispose(target, () => {
6540
6802
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
6541
6803
  const _composer = composer;
6542
6804
  // remove composer instance from DOM for intlify-devtools
@@ -6552,7 +6814,7 @@ function setupLifeCycle(i18n, target, composer) {
6552
6814
  dispose();
6553
6815
  delete _composer[DisposeSymbol];
6554
6816
  }
6555
- }, target);
6817
+ });
6556
6818
  }
6557
6819
  const globalExportProps = [
6558
6820
  'locale',