Skip to content

Commit 9684e79

Browse files
fix(credential-groups): hydrate the list cache with the whole response
The settings prefetch seeded the shared list key with only the groups array, so every consumer read an empty list for as long as the hydrated value stayed fresh. Also resets the account-type filter when a group opens or closes, alongside the tab it already reset.
1 parent eaf7d38 commit 9684e79

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

apps/sim/app/workspace/[workspaceId]/settings/[section]/prefetch.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ describe('credential-groups prefetch', () => {
7474
createdAt: '2026-01-01T00:00:00.000Z',
7575
updatedAt: '2026-01-01T00:00:00.000Z',
7676
}
77-
mockExecute.mockResolvedValue({ credentialGroups: [{ ...credentialGroup, internal: true }] })
77+
mockExecute.mockResolvedValue({
78+
credentialGroups: [{ ...credentialGroup, internal: true }],
79+
availableProviders: ['gmail'],
80+
})
7881
const queryClient = new QueryClient()
7982

8083
await SECTION_PREFETCHERS['credential-groups']?.(queryClient, {
@@ -86,7 +89,15 @@ describe('credential-groups prefetch', () => {
8689
principal: { kind: 'session', userId: 'u1', sessionId: 's1' },
8790
input: { workspaceId: 'w1' },
8891
})
89-
expect(queryClient.getQueryData(credentialGroupKeys.list('w1'))).toEqual([credentialGroup])
92+
/**
93+
* The whole response envelope, not just the groups array: this key is shared with
94+
* `fetchCredentialGroupSettings`, and seeding it with a narrower shape would leave every
95+
* consumer reading an empty list for as long as the hydrated value stayed fresh.
96+
*/
97+
expect(queryClient.getQueryData(credentialGroupKeys.list('w1'))).toEqual({
98+
credentialGroups: [credentialGroup],
99+
availableProviders: ['gmail'],
100+
})
90101
})
91102

92103
it('leaves the cache empty when the use case denies the viewer', async () => {

apps/sim/app/workspace/[workspaceId]/settings/[section]/prefetch.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ async function prefetchCredentialGroups(
3939
principal,
4040
input: { workspaceId },
4141
})
42-
return listCredentialGroupsContract.response.schema.parse(result).credentialGroups
42+
/**
43+
* Hydrates the whole response envelope, matching what `fetchCredentialGroupSettings` caches
44+
* under this key. Narrowing to the groups array here would seed the shared entry with a
45+
* shape its consumers do not read, so every one of them would see an empty list until the
46+
* first refetch replaced it.
47+
*/
48+
return listCredentialGroupsContract.response.schema.parse(result)
4349
},
4450
staleTime: CREDENTIAL_GROUP_LIST_STALE_TIME,
4551
})

apps/sim/ee/credential-groups/components/credential-groups-settings.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { useQueryState } from 'nuqs'
88
import {
99
credentialGroupIdParam,
1010
credentialGroupIdUrlKeys,
11+
credentialGroupProviderSearchParam,
12+
credentialGroupProviderSearchUrlKeys,
1113
credentialGroupTabParam,
1214
credentialGroupTabUrlKeys,
1315
} from '@/app/workspace/[workspaceId]/settings/[section]/search-params'
@@ -47,13 +49,20 @@ export function CredentialGroupsSettings({ workspaceId }: CredentialGroupsSettin
4749
...credentialGroupTabParam.parser,
4850
...credentialGroupTabUrlKeys,
4951
})
52+
/** Scoped to one group's account types for the same reason, and reset on the same transitions. */
53+
const [, setProviderSearch] = useQueryState(credentialGroupProviderSearchParam.key, {
54+
...credentialGroupProviderSearchParam.parser,
55+
...credentialGroupProviderSearchUrlKeys,
56+
})
5057
const openGroup = (groupId: string) => {
5158
void setSelectedGroupId(groupId)
5259
void setSelectedTab(null)
60+
void setProviderSearch(null)
5361
}
5462
const closeGroup = () => {
5563
void setSelectedGroupId(null, { history: 'replace' })
5664
void setSelectedTab(null)
65+
void setProviderSearch(null)
5766
}
5867
const selectedGroup = selectedGroupId
5968
? groups.find((group) => group.id === selectedGroupId)

0 commit comments

Comments
 (0)