Skip to content

Commit 26d2395

Browse files
committed
fix: return empty string for defaultFeature when enabled list is empty
Avoids inconsistency where defaultFeature would resolve to 'dashboard' but isFeatureEnabled('dashboard') returns false. When no features are enabled, defaultFeature is now an empty string.
1 parent 31ea544 commit 26d2395

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

frontend/src/hooks/__tests__/use-tenant-features.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,22 @@ describe('useTenantFeatures', () => {
138138
// Should fall back to first enabled feature, not the disabled default
139139
expect(result.current.defaultFeature).toBe('accounts')
140140
})
141+
142+
it('returns empty string for defaultFeature when no features are enabled', () => {
143+
vi.mocked(useTenantContext).mockReturnValue(
144+
makeContext({
145+
tenantConfig: {
146+
features: {
147+
enabled: [],
148+
},
149+
},
150+
}),
151+
)
152+
153+
const { result } = renderHook(() => useTenantFeatures())
154+
155+
// No enabled features — defaultFeature must not point to a disabled feature
156+
expect(result.current.defaultFeature).toBe('')
157+
expect(result.current.isFeatureEnabled('dashboard')).toBe(false)
158+
})
141159
})

frontend/src/hooks/use-tenant-features.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ export function useTenantFeatures(): TenantFeaturesResult {
2222
const enabledFeatures = config.features?.enabled ?? [...ALL_FEATURES]
2323
const enabledSet = new Set<string>(enabledFeatures)
2424

25-
// Fall back to the first enabled feature if the configured default is not in the enabled list
25+
// Fall back to the first enabled feature if the configured default is not in the enabled list.
26+
// When no features are enabled at all, defaultFeature is an empty string (no valid default).
2627
const configuredDefault = config.features?.defaultFeature ?? 'dashboard'
2728
const defaultFeature = enabledSet.has(configuredDefault)
2829
? configuredDefault
29-
: (enabledFeatures[0] ?? 'dashboard')
30+
: (enabledFeatures[0] ?? '')
3031

3132
return {
3233
isFeatureEnabled: (feature: string) => enabledSet.has(feature),

0 commit comments

Comments
 (0)