Skip to content

Commit 41eb457

Browse files
Fix desktop menu docs links regression (#7181)
## Summary - make `useExternalLink` rely on the global i18n locale so it can be used safely outside setup - restore `electronAdapter` to use the shared `useExternalLink` helper for docs URLs and static links ## Motivation Desktop menu items disappeared because a top-level call to `useExternalLink` in `electronAdapter` triggered `useI18n` at module-eval time, throwing and blocking extension registration. By making the composable global-locale-only and using it in `electronAdapter`, the module can load without setup context while preserving link behavior. ## Testing - pnpm typecheck - pnpm lint:fix ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7181-Fix-desktop-menu-docs-links-regression-2c06d73d36508157ae48cff078b9173e) by [Unito](https://www.unito.io)
1 parent f0a99a0 commit 41eb457

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/composables/useExternalLink.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { computed } from 'vue'
22

33
import { electronAPI, isElectron } from '@/utils/envUtil'
4-
import { useI18n } from 'vue-i18n'
4+
import { i18n } from '@/i18n'
55

66
/**
77
* Composable for building docs.comfy.org URLs with automatic locale and platform detection
@@ -23,7 +23,7 @@ import { useI18n } from 'vue-i18n'
2323
* ```
2424
*/
2525
export function useExternalLink() {
26-
const { locale } = useI18n()
26+
const locale = computed(() => String(i18n.global.locale.value))
2727

2828
const isChinese = computed(() => {
2929
return locale.value === 'zh' || locale.value === 'zh-TW'

tests-ui/tests/composables/useExternalLink.test.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
import { beforeEach, describe, expect, it, vi } from 'vitest'
2-
import { ref } from 'vue'
3-
4-
import { useExternalLink } from '@/composables/useExternalLink'
52

63
// Mock the environment utilities
74
vi.mock('@/utils/envUtil', () => ({
85
isElectron: vi.fn(),
96
electronAPI: vi.fn()
107
}))
118

12-
// Mock vue-i18n
13-
const mockLocale = ref('en')
14-
vi.mock('vue-i18n', () => ({
15-
useI18n: vi.fn(() => ({
16-
locale: mockLocale
17-
}))
9+
// Provide a minimal i18n instance for the composable
10+
const i18n = vi.hoisted(() => ({
11+
global: {
12+
locale: {
13+
value: 'en'
14+
}
15+
}
16+
}))
17+
vi.mock('@/i18n', () => ({
18+
i18n
1819
}))
1920

2021
// Import after mocking to get the mocked versions
22+
import { useExternalLink } from '@/composables/useExternalLink'
2123
import { electronAPI, isElectron } from '@/utils/envUtil'
2224

2325
describe('useExternalLink', () => {
2426
beforeEach(() => {
2527
vi.clearAllMocks()
2628
// Reset to default state
27-
mockLocale.value = 'en'
29+
i18n.global.locale.value = 'en'
2830
vi.mocked(isElectron).mockReturnValue(false)
2931
})
3032

@@ -53,31 +55,31 @@ describe('useExternalLink', () => {
5355

5456
describe('buildDocsUrl', () => {
5557
it('should build basic docs URL without locale', () => {
56-
mockLocale.value = 'en'
58+
i18n.global.locale.value = 'en'
5759
const { buildDocsUrl } = useExternalLink()
5860

5961
const url = buildDocsUrl('/changelog')
6062
expect(url).toBe('https://docs.comfy.org/changelog')
6163
})
6264

6365
it('should build docs URL with Chinese (zh) locale when requested', () => {
64-
mockLocale.value = 'zh'
66+
i18n.global.locale.value = 'zh'
6567
const { buildDocsUrl } = useExternalLink()
6668

6769
const url = buildDocsUrl('/changelog', { includeLocale: true })
6870
expect(url).toBe('https://docs.comfy.org/zh-CN/changelog')
6971
})
7072

7173
it('should build docs URL with Chinese (zh-TW) locale when requested', () => {
72-
mockLocale.value = 'zh-TW'
74+
i18n.global.locale.value = 'zh-TW'
7375
const { buildDocsUrl } = useExternalLink()
7476

7577
const url = buildDocsUrl('/changelog', { includeLocale: true })
7678
expect(url).toBe('https://docs.comfy.org/zh-CN/changelog')
7779
})
7880

7981
it('should not include locale for English when requested', () => {
80-
mockLocale.value = 'en'
82+
i18n.global.locale.value = 'en'
8183
const { buildDocsUrl } = useExternalLink()
8284

8385
const url = buildDocsUrl('/changelog', { includeLocale: true })
@@ -92,7 +94,7 @@ describe('useExternalLink', () => {
9294
})
9395

9496
it('should add platform suffix when requested', () => {
95-
mockLocale.value = 'en'
97+
i18n.global.locale.value = 'en'
9698
vi.mocked(isElectron).mockReturnValue(true)
9799
vi.mocked(electronAPI).mockReturnValue({
98100
getPlatform: () => 'darwin'
@@ -104,7 +106,7 @@ describe('useExternalLink', () => {
104106
})
105107

106108
it('should add platform suffix with trailing slash', () => {
107-
mockLocale.value = 'en'
109+
i18n.global.locale.value = 'en'
108110
vi.mocked(isElectron).mockReturnValue(true)
109111
vi.mocked(electronAPI).mockReturnValue({
110112
getPlatform: () => 'win32'
@@ -116,7 +118,7 @@ describe('useExternalLink', () => {
116118
})
117119

118120
it('should combine locale and platform', () => {
119-
mockLocale.value = 'zh'
121+
i18n.global.locale.value = 'zh'
120122
vi.mocked(isElectron).mockReturnValue(true)
121123
vi.mocked(electronAPI).mockReturnValue({
122124
getPlatform: () => 'darwin'
@@ -133,7 +135,7 @@ describe('useExternalLink', () => {
133135
})
134136

135137
it('should not add platform when not desktop', () => {
136-
mockLocale.value = 'en'
138+
i18n.global.locale.value = 'en'
137139
vi.mocked(isElectron).mockReturnValue(false)
138140

139141
const { buildDocsUrl } = useExternalLink()

0 commit comments

Comments
 (0)