Data prefetch happening during "next build". How to configure/stop it?
Answered
Pin-tailed Snipe posted this in #help-forum
Pin-tailed SnipeOP
I am using Tanstack query v5 to prefetch the initial infiniteQuery get request in the top RSC component using HydrationBoundary and hydrate and dehydrate Tanstack API. When testing locally, I can see that I get the initial data instantly with no network request. So far everything is great!
The problem is that we are working in a SaaS environment with multitenancy.
Because we have different subscribers, the setup of the correct backend URL prefix is a challenge during the data prefetch while "next build" is running, because at that point in time, we don't know the tenant/subscriber yet. This build process is happening on the developer machine and the build folder is being sent to the correct cloud environment. Is there a possible way to tell NextJS to not prefetch during build for the time being?
The problem is that we are working in a SaaS environment with multitenancy.
Because we have different subscribers, the setup of the correct backend URL prefix is a challenge during the data prefetch while "next build" is running, because at that point in time, we don't know the tenant/subscriber yet. This build process is happening on the developer machine and the build folder is being sent to the correct cloud environment. Is there a possible way to tell NextJS to not prefetch during build for the time being?
Answered by Asian paper wasp
It sounds like to me that some of the pages are statically build, while the BE URL are expected to be dynamic.
So I guess it makes sense to make every page dynamic for this case.
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
So I guess it makes sense to make every page dynamic for this case.
export const dyanmic = 'force-dynamic'https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
3 Replies
Asian paper wasp
It sounds like to me that some of the pages are statically build, while the BE URL are expected to be dynamic.
So I guess it makes sense to make every page dynamic for this case.
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
So I guess it makes sense to make every page dynamic for this case.
export const dyanmic = 'force-dynamic'https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic
Answer
Asian paper wasp
BTW, the
next build result tells you which pages are statically build, which are dynamicPin-tailed SnipeOP
Thanks, it's a good tradeoff for the time being!