I've encountered a problem with updating data on a basic data page. The situation is simple: there's a page that shows category data and another page that allows editing of the same data. After making edits and returning to the list page, I expect the list to reflect the changes. However, since it's a Static Site Generation (SSG) page, it generates static data at build time.
import prismadb from "@/lib/prismadb";
import CategoriesClient from "./components/client";
export const dynamic = "force-dynamic";
export default async function Categories(res) {
let categories;
categories = await prismadb.category.findMany({
orderBy: {
createdAt: "desc",
},
});
const formattedCategories = categories.map((category) => ({
id: category.id,
name: category.name,
isActive: category.isActive,
}));
return (
<>
<CategoriesClient data={formattedCategories} />
</>
);
}
async function onSubmit(data) {
try {
setLoading(true);
if (initialData) {
await axios.patch(`/api/categories/${params.categoryId}`, data);
} else {
await axios.post(`/api/categories`, data);
}
router.refresh();
router.push(`/categories`);
toast.success(successMessage);
} catch (err) {
toast.error(`An error as occurred: ${err.response.data}`);
} finally {
setLoading(false);
}
}
I have attempted using the revalidate property on the list page, but it only works with a hard refresh, not with the router which I am currently using.
export const revalidate = 1;
At present, I'm utilizing force-dynamic to make the page dynamic. However, when I navigate to the page through the router or Next.js Link, everything functions correctly. Yet, when I manually refresh the page with F5 or input the link directly, I encounter a 500 error (only in the production environment on Netlify, local machine works fine).
Is there a solution to ensure that the page updates accurately in all scenarios, including manual refreshes?
I would greatly appreciate any assistance with this issue as I have been struggling with it for days.