Skip to content

Commit 214a19d

Browse files
committed
fix(queries): forward the abort signal to getFullOrganization
useOrganization destructured `signal` from the queryFn and passed it to fetchOrganization, which named the parameter `_signal` and never used it — so the org detail fetch could not be cancelled. Switching orgs rapidly left every prior request in flight, free to resolve out of order. Better Auth takes cancellation two ways and both are already used here: fetchOptions on the params object (session.ts:21) and a second argument (admin-users.ts:129). Uses the former. This was the only `_signal` under apps/sim/hooks. The existing transition test asserted the exact call shape, so it now asserts intent via objectContaining. Adds a test for the signal itself; it fails against the old code.
1 parent 13259cb commit 214a19d

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

apps/sim/hooks/queries/organization.test.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,19 @@ describe('organization identity transitions', () => {
189189
expect(container).not.toHaveTextContent('Member A')
190190
expect(container).not.toHaveTextContent('org-a')
191191
expect(container.querySelector('button')).toBeNull()
192-
expect(mockGetFullOrganization).toHaveBeenCalledWith({
193-
query: { organizationId: 'org-b' },
194-
})
192+
expect(mockGetFullOrganization).toHaveBeenCalledWith(
193+
expect.objectContaining({ query: { organizationId: 'org-b' } })
194+
)
195+
})
196+
197+
it('forwards the query signal so an in-flight org fetch can be cancelled', async () => {
198+
mockGetFullOrganization.mockResolvedValue({ data: ORGANIZATION_A })
199+
200+
renderOrganization('org-a')
201+
202+
await flushQueries()
203+
204+
const [args] = mockGetFullOrganization.mock.calls[0]
205+
expect(args.fetchOptions?.signal).toBeInstanceOf(AbortSignal)
195206
})
196207
})

apps/sim/hooks/queries/organization.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,10 @@ export function useMemberRemovalImpact(
154154
* (no cross-org cache collision). The active-org caller passes the active org's
155155
* id, so its behavior is unchanged.
156156
*/
157-
async function fetchOrganization(orgId: string, _signal?: AbortSignal) {
157+
async function fetchOrganization(orgId: string, signal?: AbortSignal) {
158158
const response = await client.organization.getFullOrganization({
159159
query: { organizationId: orgId },
160+
fetchOptions: { signal },
160161
})
161162
return response.data
162163
}

0 commit comments

Comments
 (0)