@@ -591,8 +591,13 @@ export function createI18n(options: any = {}, VueI18nLegacy?: any): any {
591
591
}
592
592
593
593
// global method and properties injection for Composition API
594
+ let globalReleaseHandler : ReturnType < typeof injectGlobalFields > | null =
595
+ null
594
596
if ( ! __legacyMode && __globalInjection ) {
595
- injectGlobalFields ( app , i18n . global as Composer )
597
+ globalReleaseHandler = injectGlobalFields (
598
+ app ,
599
+ i18n . global as Composer
600
+ )
596
601
}
597
602
598
603
// install built-in components and directive
@@ -614,6 +619,7 @@ export function createI18n(options: any = {}, VueI18nLegacy?: any): any {
614
619
// release global scope
615
620
const unmountApp = app . unmount
616
621
app . unmount = ( ) => {
622
+ globalReleaseHandler && globalReleaseHandler ( )
617
623
i18n . dispose ( )
618
624
unmountApp ( )
619
625
}
@@ -1650,7 +1656,12 @@ const globalExportMethods = !__LITE__
1650
1656
? [ 't' , 'rt' , 'd' , 'n' , 'tm' , 'te' ]
1651
1657
: [ 't' ]
1652
1658
1653
- function injectGlobalFields ( app : App , composer : Composer ) : void {
1659
+ type GlobalInjectionReleaseHandler = ( ) => void
1660
+
1661
+ function injectGlobalFields (
1662
+ app : App ,
1663
+ composer : Composer
1664
+ ) : GlobalInjectionReleaseHandler {
1654
1665
const i18n = Object . create ( null )
1655
1666
globalExportProps . forEach ( prop => {
1656
1667
const desc = Object . getOwnPropertyDescriptor ( composer , prop )
@@ -1683,6 +1694,17 @@ function injectGlobalFields(app: App, composer: Composer): void {
1683
1694
}
1684
1695
Object . defineProperty ( app . config . globalProperties , `$${ method } ` , desc )
1685
1696
} )
1697
+
1698
+ const release = ( ) => {
1699
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1700
+ delete ( app as any ) . config . globalProperties . $i18n
1701
+ globalExportMethods . forEach ( method => {
1702
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1703
+ delete ( app as any ) . config . globalProperties [ `$${ method } ` ]
1704
+ } )
1705
+ }
1706
+
1707
+ return release
1686
1708
}
1687
1709
1688
1710
function injectGlobalFieldsForBridge (
0 commit comments