From cc2dcaa306d8a4d3ec9b42b7fbeba02dfd0fc205 Mon Sep 17 00:00:00 2001 From: Prasanna721 <106952318+Prasanna721@users.noreply.github.com> Date: Thu, 19 Feb 2026 06:54:32 +0000 Subject: [PATCH] fix: space deletion not switching to Nova Spaces and new space not appearing in dropdown (#747) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### fix: space selector state bugs on create and delete Two related bugs in the space selector caused by query cache key mismatches in `use-project-mutations.ts`: 1. New spaces not appearing in dropdown until refresh — wrong query cache was being invalidated after creation. 2. App stuck on deleted space instead of switching to Nova Spaces — delete handler was reading from an empty cache, so the selection never updated. --- apps/web/hooks/use-project-mutations.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/web/hooks/use-project-mutations.ts b/apps/web/hooks/use-project-mutations.ts index b9573edb..d9cfa335 100644 --- a/apps/web/hooks/use-project-mutations.ts +++ b/apps/web/hooks/use-project-mutations.ts @@ -4,7 +4,7 @@ import { $fetch } from "@lib/api" import { useMutation, useQueryClient } from "@tanstack/react-query" import { toast } from "sonner" import { useProject } from "@/stores" -import type { Project } from "@repo/lib/types" +import type { ContainerTagListType } from "@repo/lib/types" export function useProjectMutations() { const queryClient = useQueryClient() @@ -29,6 +29,7 @@ export function useProjectMutations() { onSuccess: (data) => { toast.success("Project created successfully!") queryClient.invalidateQueries({ queryKey: ["projects"] }) + queryClient.invalidateQueries({ queryKey: ["container-tags"] }) if (data?.containerTag) { setSelectedProjects([data.containerTag]) @@ -63,14 +64,12 @@ export function useProjectMutations() { }, onSuccess: (_, variables) => { toast.success("Project deleted successfully") - queryClient.invalidateQueries({ queryKey: ["projects"] }) - queryClient.invalidateQueries({ queryKey: ["container-tags"] }) - const allProjects = - queryClient.getQueryData(["projects"]) || [] - const deletedProject = allProjects.find( - (p) => p.id === variables.projectId, - ) + const allTags = + queryClient.getQueryData(["container-tags"]) || + [] + const deletedProject = allTags.find((p) => p.id === variables.projectId) + if ( deletedProject?.containerTag && selectedProjects.includes(deletedProject.containerTag) @@ -79,6 +78,9 @@ export function useProjectMutations() { selectedProjects.filter((tag) => tag !== deletedProject.containerTag), ) } + + queryClient.invalidateQueries({ queryKey: ["projects"] }) + queryClient.invalidateQueries({ queryKey: ["container-tags"] }) }, onError: (error) => { toast.error("Failed to delete project", {