Nextjs navigation after trpc mutation

I just found we have an issue while navigatig in browsers like safari/firefox but all working on chrome where after mutation I direct the user to the dashboard page where it should render new created data in the table. This bit of code after successful mutation it directs the user to the home page I can see it re-renders the server component and trpc query for table data is being trigerred but it still contains data - 1. After full browser refresh it contains data +1. Am I doing something wrong with refreshing next cache or somethign?
const createMutation = api.location.create.useMutation({
onSuccess: () => {
reset(getValues());
onSuccessCallback?.();
setTimeout(() => {
router.push('/locations');
router.refresh();
void apiUtils.invalidate();
}, 1000);
},
});
const createMutation = api.location.create.useMutation({
onSuccess: () => {
reset(getValues());
onSuccessCallback?.();
setTimeout(() => {
router.push('/locations');
router.refresh();
void apiUtils.invalidate();
}, 1000);
},
});
2 Replies
rocawear
rocawear2mo ago
Have you tested to await the router.push
Mugetsu
MugetsuOP2mo ago
Im on 14.2.23 router.push is void non promise. Throws error when awaited.

Did you find this page helpful?