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 <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-07 17:37:16 +00:00
parent 8f7f5b3a88
commit 0b475d8e03
2 changed files with 10 additions and 1 deletions

View file

@ -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 }),
});

View file

@ -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();
},
});