Next.js Discord

Discord Forum

RSC and Cache problems

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
Hi I'm trying to work out how I make the RSC requests work with a CDN when self hosting Nextjs. Is there any more info on this subject. I'm working on an ecommerce site with 100,000 products. Those products could appear in numerous product listing pages (search result pages). Each of those PLP pages are given unique URLs for SEO purposes. Example URLs:

/mens/
/mens/trainers
/mens/trainers/brand
/mens/trainers/brand?facet-price=%3A168

They could all have the same products in. Due to the way the rsc hash is calculated that means I get a different _rsc params on each listing page, even though the contents of that response is exactly the same.

product/299336/?_rsc=1vl30
product/299336/?_rsc=qe3go
product/299336/?_rsc=1vg99

I have even gone to different areas of the site cart, checkout, order history, all with links back to the same product, they each produce different _rsc params, but still the data returned is identical?
On a high throughput site I want to be able to cache identical data in the CDN close to the customer. At the moment that would be impossible as there would be to many variations on the rsc hash to make the caching effective.
2 possible options:

Cache all rsc requests in the CDN - this would end up caching loads of duplicate data and get cache misses when they should be hits
Pass all request through to the Nextjs server - With this solution I would worry the server would be overloaded at peak periods.

Why the rsc hash is different when it is always returning identical data? What is the purpose of this hash? As mentioned before could this just be set to _rsc=1? We would also have issues with the Vary header as it is currently returned like this: Vary: RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url

In this case the Next-Router-State-Tree and Next-Url will be set on where you are coming from and do not necessarily have an impact on the data need for the page we are going to. The Vary header will again have an impact on the CDN

9 Replies

Transvaal lion
Having the same issue. Did you came up with any solution? Guess there is a bigger github discussion going on: https://github.com/vercel/next.js/discussions/59167 but no real feedback from next team so far
Very interesting issue, I feel like that's maybe something you'd want to escalate and work directly with Next.js core team, if by any chance you have skilled developers willing to contribute (I don't have special way to reach them out in this case, maybe shouting a good old email or a tweet would work)
Could intercept route help here ?
basically what you want is being able to cache at component level not page level
however all component-level patterns are brand new: think of Supsense that allow you to fetch data from a server component rather than having to rely on page level "getServerSideProps" everytime
PPR is another example of component level pattern that is not even there, allowing to dynamically load some component
Your use case is the reverse, you kinda want a static component
You may want to explore the code to see how this hash is generated too, what you would need here is a capacity to generate your own hash I guess eg taking the productId into account
To be fair the github ticket is a bit hard to read, you might want to craft a clearer minimal repro with precise examples
it's not a github issue but a discussion too so you'll never have an official answer here, you need an issue ticket