Cache Components with params and Multi Tenant Applications #85239
-
|
If you look at the platforms starter kit, https://vercel.com/templates/next.js/platforms-starter-kit The domain gets passed into the nextjs pages via a param in the middleware/proxy. However params are considered runtime and thus cannot be passed into a "use cache" function as far as I can tell from the docs
So from what I can tell unless you have the full list of all domains at build time via generateStaticParams, you can't use cache components to cache each domains shell. Adding a new domain would then involve a complete rebuild of the applicaiton. Is this correct? It would be nice if it was possible to "use cache" with runtime information (particularly params) and nextjs would support building the static parts on first request rather than requiring a build time pre-render of all the static parts. Especially since nextjs already supports revalidating and rebuilding the static parts at runtime this doesn't seem like it would be too much of a stretch? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
Ah, looks like an upcoming feature called "use cache: remote" is what is intended to enable this functionality. https://nextjs.org/docs/app/api-reference/directives/use-cache-remote However it looks like the components still need Suspense boundaries so it won't be part of the pre-rendered instant shell when doing page navigations is my guess. So won't really be good for using with entire Layouts. My feedback is to roll the behavior of "use cache: remote" into "use cache" so that it enables the same use cache behavior and semantics (ie no suspense boundaries, part of instant page load shell) without requiring build time compilation of everything ahead of time. Can still do build time up until dynamic sections. First request has a delay to compute cached data, subsequent requests are fast. |
Beta Was this translation helpful? Give feedback.
-
|
@rshaul what you want is See my reply here (the explainer below the first paragraphs): Set |
Beta Was this translation helpful? Give feedback.
-
|
Doing some testing I think the behavior I had requested with "use cache" all works out of the box already with generateStaticParams returning at least 1 value in the root layout. No root-params or use cache: remote needed Just the way the documentation was written was confusing, but I think the behavior is all there that I want. Thanks guys. |
Beta Was this translation helpful? Give feedback.
Doing some testing I think the behavior I had requested with "use cache" all works out of the box already with generateStaticParams returning at least 1 value in the root layout.
No root-params or use cache: remote needed
Just the way the documentation was written was confusing, but I think the behavior is all there that I want. Thanks guys.