Skip to content

Commit 1ea6755

Browse files
s00dcursoragent
andcommitted
fix(core): normalize empty activeRoute for Active tags
Keep chunk Active tags in sync with key-level active detection. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 51979f7 commit 1ea6755

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

packages/core/src/devtools.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ export function flattenTranslationNode(obj: Record<string, unknown>, parentSegme
162162

163163
export function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevtoolsInspectorNode[] {
164164
const parsed = parseInspectorNodeId(options.nodeId)
165+
const activeLocale = options.activeLocale
166+
const activeRoute = options.activeRouteName || 'index'
165167

166168
if (parsed.kind === 'root') {
167169
const locales = collectLocaleCodes(options.storage, options.configuredLocales)
168170
const nodes: I18nDevtoolsInspectorNode[] = [
169171
{
170172
id: NODE_ACTIVE,
171-
label: `Active (${options.activeLocale}:${options.activeRouteName || 'index'})`,
173+
label: `Active (${activeLocale}:${activeRoute})`,
172174
tags: [ACTIVE_TAG],
173175
},
174176
]
@@ -180,7 +182,7 @@ export function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevt
180182
nodes.push({
181183
id: `${PREFIX_LOCALE}${code}`,
182184
label: configured?.displayName ? `${code} (${configured.displayName})` : code,
183-
tags: code === options.activeLocale ? [{ ...ACTIVE_TAG, tooltip: 'Active locale' }] : undefined,
185+
tags: code === activeLocale ? [{ ...ACTIVE_TAG, tooltip: 'Active locale' }] : undefined,
184186
})
185187

186188
// Flat chunk nodes (not nested): Vue DevTools selection is unreliable for nested
@@ -189,7 +191,7 @@ export function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevt
189191
nodes.push({
190192
id: `${PREFIX_CHUNK}${code}|${routeName}`,
191193
label: `${code}:${routeName}`,
192-
tags: activeChunkTag(code, routeName, options.activeLocale, options.activeRouteName),
194+
tags: activeChunkTag(code, routeName, activeLocale, activeRoute),
193195
})
194196
}
195197
}
@@ -198,9 +200,7 @@ export function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevt
198200
}
199201

200202
if (parsed.kind === 'active') {
201-
const locale = options.activeLocale
202-
const routeName = options.activeRouteName || 'index'
203-
return flattenTranslationNode(options.activeTranslations ?? {}).map((node) => withKeyPrefix(locale, routeName, node))
203+
return flattenTranslationNode(options.activeTranslations ?? {}).map((node) => withKeyPrefix(activeLocale, activeRoute, node))
204204
}
205205

206206
if (parsed.kind === 'locale' && parsed.locale) {
@@ -209,7 +209,7 @@ export function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevt
209209
id: `${PREFIX_CHUNK}${locale}|${routeName}`,
210210
label: routeName,
211211
children: [],
212-
tags: activeChunkTag(locale, routeName, options.activeLocale, options.activeRouteName),
212+
tags: activeChunkTag(locale, routeName, activeLocale, activeRoute),
213213
}))
214214
}
215215

@@ -225,7 +225,7 @@ export function buildInspectorTree(options: BuildInspectorTreeOptions): I18nDevt
225225
const routeName = parsed.routeName || 'index'
226226
const chunk = options.storage.translations.get(`${locale}:${routeName}`) as Record<string, unknown> | undefined
227227
const segments = parsed.segments ?? []
228-
const isActiveContext = options.activeLocale === locale && (options.activeRouteName || 'index') === routeName
228+
const isActiveContext = activeLocale === locale && activeRoute === routeName
229229
const source = isActiveContext ? (options.activeTranslations ?? chunk ?? {}) : (chunk ?? {})
230230

231231
return flattenTranslationNode(source, segments).map((node) => withKeyPrefix(locale, routeName, node))

packages/core/tests/devtools.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,21 @@ describe('devtools helpers', () => {
148148
}),
149149
).toBe(4)
150150
})
151+
152+
test('buildInspectorTree tags index chunk when activeRouteName is empty', () => {
153+
const storage = createStorage({
154+
'en:index': { hello: 'Hello' },
155+
})
156+
157+
const root = buildInspectorTree({
158+
nodeId: 'root',
159+
storage,
160+
configuredLocales: [{ code: 'en' }],
161+
activeLocale: 'en',
162+
activeRouteName: '',
163+
})
164+
165+
expect(root.find((node) => node.id === 'active')?.label).toBe('Active (en:index)')
166+
expect(root.find((node) => node.id === 'chunk|en|index')?.tags?.[0]?.label).toBe('Active')
167+
})
151168
})

0 commit comments

Comments
 (0)