From d18c3c7e44ab7d4457f588a409be9beb9aba9132 Mon Sep 17 00:00:00 2001 From: Lukas May Date: Tue, 10 Feb 2026 11:03:20 +0100 Subject: [PATCH] fix(web): Dismiss button on refine agent ChangeSetBanner now works The dismiss mutation only invalidated `listAgents` but the hook reads from `getActiveRefineAgent`, so the banner stayed visible after dismiss. Added optimistic cache clearing and invalidation for `getActiveRefineAgent`. --- packages/web/src/hooks/useRefineAgent.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/web/src/hooks/useRefineAgent.ts b/packages/web/src/hooks/useRefineAgent.ts index 202a7c4..9310c0c 100644 --- a/packages/web/src/hooks/useRefineAgent.ts +++ b/packages/web/src/hooks/useRefineAgent.ts @@ -170,26 +170,34 @@ export function useRefineAgent(initiativeId: string): UseRefineAgentResult { onMutate: async ({ id }) => { // Cancel outgoing refetches await utils.listAgents.cancel(); + await utils.getActiveRefineAgent.cancel({ initiativeId }); - // Snapshot previous value + // Snapshot previous values const previousAgents = utils.listAgents.getData(); + const previousRefineAgent = utils.getActiveRefineAgent.getData({ initiativeId }); // Optimistically remove the agent from the list utils.listAgents.setData(undefined, (old = []) => old.filter(a => a.id !== id) ); + // Optimistically clear the active refine agent so the banner disappears immediately + utils.getActiveRefineAgent.setData({ initiativeId }, null); - return { previousAgents }; + return { previousAgents, previousRefineAgent }; }, onSuccess: () => {}, onError: (err, variables, context) => { - // Revert optimistic update + // Revert optimistic updates if (context?.previousAgents) { utils.listAgents.setData(undefined, context.previousAgents); } + if (context?.previousRefineAgent !== undefined) { + utils.getActiveRefineAgent.setData({ initiativeId }, context.previousRefineAgent); + } }, onSettled: () => { void utils.listAgents.invalidate(); + void utils.getActiveRefineAgent.invalidate({ initiativeId }); }, });