Skip to content

Commit f4168dc

Browse files
committed
fix: composer instance keeping
1 parent f86fd00 commit f4168dc

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

packages/vue-i18n-core/src/devtools.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,8 @@ export async function enableDevTools(app: App, i18n: _I18n): Promise<boolean> {
6161
})
6262

6363
api.on.inspectComponent(({ componentInstance, instanceData }) => {
64-
if (
65-
componentInstance.vnode.el &&
66-
componentInstance.vnode.el.__VUE_I18N__ &&
67-
instanceData
68-
) {
69-
inspectComposer(instanceData, componentInstance.vnode.el.__VUE_I18N__ as Composer)
64+
if (componentInstance.__VUE_I18N__ && instanceData) {
65+
inspectComposer(instanceData, componentInstance.__VUE_I18N__ as Composer)
7066
}
7167
})
7268

@@ -138,9 +134,9 @@ function updateComponentTreeTags(
138134
): void {
139135
// prettier-ignore
140136
const global = i18n.global
141-
if (instance && instance.vnode.el && instance.vnode.el.__VUE_I18N__) {
137+
if (instance && instance.__VUE_I18N__) {
142138
// add custom tags local scope only
143-
if (instance.vnode.el.__VUE_I18N__ !== global) {
139+
if (instance.__VUE_I18N__ !== global) {
144140
const tag = {
145141
label: `i18n (${getI18nScopeLable(instance)} Scope)`,
146142
textColor: 0x000000,

packages/vue-i18n-core/src/i18n.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,8 @@ function setupLifeCycle(
637637
// eslint-disable-next-line vue-composable/lifecycle-placement -- NOTE(kazupon): not Vue component
638638
onMounted(() => {
639639
// inject composer instance to DOM for intlify-devtools
640-
// @ts-expect-error -- TODO(kazupon): need to fix types
641-
if ((__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) && !__NODE_JS__ && target.vnode.el) {
642-
// @ts-expect-error -- TODO(kazupon): need to fix types
643-
target.vnode.el.__VUE_I18N__ = composer
640+
if ((__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) && !__NODE_JS__) {
641+
target.__VUE_I18N__ = composer
644642
emitter = createEmitter<VueDevToolsEmitterEvents>()
645643
// eslint-disable-next-line @typescript-eslint/no-explicit-any
646644
const _composer = composer as any
@@ -655,18 +653,10 @@ function setupLifeCycle(
655653
const _composer = composer as any
656654

657655
// remove composer instance from DOM for intlify-devtools
658-
if (
659-
(__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) &&
660-
!__NODE_JS__ &&
661-
// @ts-expect-error -- TODO(kazupon): need to fix types
662-
target.vnode.el &&
663-
// @ts-expect-error -- TODO(kazupon): need to fix types
664-
target.vnode.el.__VUE_I18N__
665-
) {
656+
if ((__DEV__ || __FEATURE_PROD_VUE_DEVTOOLS__) && !__NODE_JS__ && target.__VUE_I18N__) {
666657
emitter && emitter.off('*', addTimelineEvent)
667658
_composer[DisableEmitter] && _composer[DisableEmitter]()
668-
// @ts-expect-error -- TODO(kazupon): need to fix types
669-
delete target.vnode.el.__VUE_I18N__
659+
delete target.__VUE_I18N__
670660
}
671661
i18n.__deleteInstance(target)
672662

packages/vue-i18n-core/src/vue.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { InjectionKey } from 'vue'
2+
import type { Composer } from './composer'
23
import type { I18n, I18nInternal } from './i18n'
34

45
declare module 'vue' {
@@ -17,6 +18,11 @@ declare module 'vue' {
1718
* whether target component is custom element
1819
*/
1920
isCE?: boolean
21+
/**
22+
* @internal
23+
* for vue/devtools i18n composer hook
24+
*/
25+
__VUE_I18N__?: Composer
2026
}
2127

2228
export interface GenericComponentInstance {
@@ -25,5 +31,10 @@ declare module 'vue' {
2531
* whether target component is custom element
2632
*/
2733
isCE?: boolean
34+
/**
35+
* @internal
36+
* for vue/devtools i18n composer hook
37+
*/
38+
__VUE_I18N__?: Composer
2839
}
2940
}

0 commit comments

Comments
 (0)