From 0b475d8e0342a38dd5ebe5b1849cce4af803c26f Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 7 Jul 2026 17:37:16 +0000 Subject: [PATCH] fix(portfolio): refresh server-rendered data after adding properties or saving a scenario Both mutations navigated with router.push alone, so the destination served the pre-mutation render from the client router cache: new properties were missing from the portfolio table (compounded by useProperties' 5-minute staleTime, now invalidated too) and a first scenario still showed "No scenarios yet". router.refresh() after push busts the cache. Co-Authored-By: Claude Fable 5 --- .../(portfolio)/scenarios/new/NewScenarioJourney.tsx | 7 ++++++- .../[slug]/properties/add/AddPropertiesClient.tsx | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/portfolio/[slug]/(portfolio)/scenarios/new/NewScenarioJourney.tsx b/src/app/portfolio/[slug]/(portfolio)/scenarios/new/NewScenarioJourney.tsx index 3fc372bc..7073ff7e 100644 --- a/src/app/portfolio/[slug]/(portfolio)/scenarios/new/NewScenarioJourney.tsx +++ b/src/app/portfolio/[slug]/(portfolio)/scenarios/new/NewScenarioJourney.tsx @@ -90,7 +90,12 @@ export function NewScenarioJourney({ }); if (!res.ok) throw new Error((await res.json()).error ?? "Save failed"); }, - onSuccess: () => router.push(`/portfolio/${portfolioId}/scenarios`), + onSuccess: () => { + router.push(`/portfolio/${portfolioId}/scenarios`); + // The scenarios list is server-rendered; without a refresh the client + // router cache serves the pre-save page ("No scenarios yet"). + router.refresh(); + }, onError: (e: Error) => setErrors({ excl: e.message }), }); diff --git a/src/app/portfolio/[slug]/properties/add/AddPropertiesClient.tsx b/src/app/portfolio/[slug]/properties/add/AddPropertiesClient.tsx index 1e9ed6a1..40b63237 100644 --- a/src/app/portfolio/[slug]/properties/add/AddPropertiesClient.tsx +++ b/src/app/portfolio/[slug]/properties/add/AddPropertiesClient.tsx @@ -93,6 +93,10 @@ export default function AddPropertiesClient({ setDone(totals); // Added properties change the search's alreadyInPortfolio flags queryClient.invalidateQueries(["postcode-search", portfolioId]); + // …and the portfolio's property table, which otherwise stays stale for + // 5 minutes (useProperties staleTime) on top of the router cache. + queryClient.invalidateQueries(["properties", portfolioId]); + router.refresh(); }, });