Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import PasswordExpired from './pages/PasswordExpired.vue'
import TermsAndConditions from './pages/TermsAndConditions.vue'
import UnverifiedEmail from './pages/UnverifiedEmail.vue'

import product from '@/services/product.js'
import { useAccountAuthStore } from '@/stores/account-auth.js'
import { useAccountSettingsStore } from '@/stores/account-settings.js'
import { useContextStore } from '@/stores/context.js'
Expand Down Expand Up @@ -118,7 +119,7 @@ export default {
...mapState(useAccountAuthStore, ['user']),
...mapState(useUxLoadingStore, ['appLoader', 'offline']),
...mapState(useAccountSettingsStore, ['settings']),
...mapState(useContextStore, ['instance', 'device']),
...mapState(useContextStore, ['instance', 'device', 'team']),
pageTitleSignal () {
return [this.instance?.id, this.instance?.name, this.device?.id, this.device?.name, this.$route.name]
},
Expand Down Expand Up @@ -168,6 +169,21 @@ export default {
const title = computePageTitle(this.$route, { instance: this.instance, device: this.device })
if (title) document.title = title
}
},
'team.id': {
immediate: true,
handler (teamId, oldTeamId) {
// PostHog evaluates its flags as soon as it initialises, before we know
// which team the user is in - so anything targeting the team group comes
// back false. On a hard refresh the team is rehydrated from sessionStorage
// and account.setTeam early-returns, so nothing ever tells PostHog about
// it. Registering the group here triggers a re-evaluation. First team of
// this page load only: real team switches already go through
// product.setTeam.
if (!oldTeamId && teamId) {
product.setTeam(this.team)
}
}
}
},
mounted () {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/frontend/stores/account-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('account-settings store', () => {
beforeEach(() => {
setActivePinia(createPinia())
vi.clearAllMocks()
delete window.posthog
mockAuth()
mockTeam()
})
Expand Down Expand Up @@ -83,6 +84,26 @@ describe('account-settings store', () => {
expect(store.features).toEqual({ billing: true })
})
})

describe('loadPosthogFlags', () => {
it('stores the flag values PostHog reports', () => {
const onFeatureFlags = vi.fn((cb) => cb(['MCP_THIRD_PARTY'], { MCP_THIRD_PARTY: true }))
window.posthog = { onFeatureFlags }

const store = useAccountSettingsStore()
store.loadPosthogFlags()

expect(store.posthogFlags).toEqual({ MCP_THIRD_PARTY: true })
})

it('does not throw when PostHog is unavailable', () => {
delete window.posthog

const store = useAccountSettingsStore()
expect(() => store.loadPosthogFlags()).not.toThrow()
expect(store.posthogFlags).toEqual({})
})
})
})

describe('getters', () => {
Expand Down
Loading