Menu

#156 fix(ui): remove deleted organization immediately from query cache and user context (#153)

open
nobody
None
2026-09-04
2026-09-03
Anonymous
No

Originally created by: amasen02

## Summary

Fixes [#153] — removes a deleted organization immediately from the UI list, infinite queries, and user organization context without requiring a manual page reload.

Root Cause

useDeleteOrganization in ui/src/features/organizations/hooks/use-organization-actions.ts did not update cached query pages upon deletion and omitted currentUserContextKey.all invalidation. Consequently:

  1. Active and cached infinite lists (platformOrganizationsKey.lists()) and the all-organizations query (platformOrganizationsKey.list({ scope: { mode: "all" } })) retained the deleted organization until the browser page was hard refreshed.
  2. The currentUserContext cache (which drives userContext.organizationUsers in the OrgSwitcher and navbar) still listed the deleted organization.

Solution

In useDeleteOrganization.onSuccess:

  1. Updated platformOrganizationsKey.lists() infinite query pages via queryClient.setQueriesData to immediately filter out the deleted organization (id !== organizationId) and decrement total.
  2. Updated platformOrganizationsKey.list({ scope: { mode: "all" } }) to filter out the deleted item and decrement total.
  3. Updated currentUserContextKey.all to immediately filter out organizationUsers where organizationId === organizationId.
  4. Evicted cached detail queries (organizationsKey.detail(organizationId) and platformOrganizationsKey.detail(organizationId)).
  5. Triggered background invalidation for organizationsKey.lists(), platformOrganizationsKey.lists(), and currentUserContextKey.all.

Verification

  • npx tsc --noEmit: 0 TypeScript errors.
  • npx next build: production build completed cleanly with Turbopack (20/20 static and dynamic routes compiled successfully).

Checklist

  • [x] Deleted organization filtered out immediately from UI state
  • [x] Cache synchronization for infinite lists and user context
  • [x] TypeScript clean and production build passed
  • [x] Staged as Draft PR

Related

Tickets: #153

Discussion


Log in to post a comment.