generateStaticParams does not load the most updated data
Unanswered
White-chinned Petrel posted this in #help-forum
White-chinned PetrelOP
Hello everyone,
I have a problem while using generateStaticParams on a page.
I have a path like "/[lang]/tools/[tool]/[subTool]"; what I am trying to do with generateStaticParams is generating an array of params.
To achieve that, I am using a GET route API (nodejs runtime, not edge) which is reading from a JSON file within the server. The issue is that I am trying to rename [tool] within my JSON file, but the generateStaticParam still loads the previous one, like it is using some sort of cache.
I have also attempted to force no cache using the following snippet:
Could be the problem the cache() statement? The weird thing is that it is working great with "npm run dev", I am getting the error only for "npm run build".
Any suggestion? Have you faced something similar?
I have a problem while using generateStaticParams on a page.
I have a path like "/[lang]/tools/[tool]/[subTool]"; what I am trying to do with generateStaticParams is generating an array of params.
To achieve that, I am using a GET route API (nodejs runtime, not edge) which is reading from a JSON file within the server. The issue is that I am trying to rename [tool] within my JSON file, but the generateStaticParam still loads the previous one, like it is using some sort of cache.
I have also attempted to force no cache using the following snippet:
const toolListByLocale: ToolList[] = await getTools(locale, {
cache: 'no-store',
});
...
export const getTools = cache(
async (lang: Locale, init?: RequestInit): Promise<ToolList[]> => {
const res = await fetch(
`${process.env.NEXT_PUBLIC_BASE_URL}/api/${lang}/tools`,
init,
);
if (!res.ok) throw new Error('Failed to fetch data');
const toolList: ToolList[] = await res.json();
return toolList;
},
);Could be the problem the cache() statement? The weird thing is that it is working great with "npm run dev", I am getting the error only for "npm run build".
Any suggestion? Have you faced something similar?
1 Reply
White-chinned PetrelOP
Find out that this is better than "cache: 'no-store'":
const { signal } = new AbortController()
fetch(url, { signal })