Open Ruchika-saini opened 10 months ago
Found this example: https://github.com/vercel/next.js/tree/canary/examples/ssr-caching
Tried this repo on local, and now I can see the response header setting the cache-control headers. But the page is not working as expected. Plus, I am running the app in production mode, first building the app, and then using "next start" to run the app. Using Next js v13.5.6.
Current Behavior: Res headers are there, but the time on the page(Time on the page) is getting updated on every request which should not be the case.
Expected Behaviour: Time on the page should not be updated on every request, it should serve the stale time value before 59s.
Please help with this, and mention the expected behavior in this case when caching is enabled in getServerSideProps.
Same issue here. We set the exact same header but we don't even see the "stale-while-revalidate" in the response.
Link to the code that reproduces this issue
https://github.com/Ruchika-saini/NextJs-swr/tree/main
To Reproduce
Current vs. Expected behavior
Expected: When checking context.response on server(checking server logs), it should set the headers as coded ctx.res.setHeader( 'Cache-Control', 'public, s-maxage=10, stale-while-revalidate=59' )
Current: Headers are not set, there is no difference in the context.response headers. when analyzed further in next JS package(v13.5.6)), there is revalidate-headers.js file which is setting the headers based on the "options" values. In my case, when checked server c logs, "options" values are coming like this options { private: false, stateful: true, revalidate: 1 }
Coming back to "options" values options { private: false, stateful: true, revalidate: 1 }
"stateful" value needs to be false to enter into revalidate condition but it is coming as true. On checking further, how "stateful" value is set in next js package: "stateful" value is decided on based of SSG or not.
stateful: !isSSG,
stateful is only going to be false when it's SSG (means page is using getStaticProps).
So, as documented here on Next JS website, that we can set stale-while-revalidate with getServerSide props as well is not going to work. https://nextjs.org/docs/pages/building-your-application/data-fetching/get-server-side-props#caching-with-server-side-rendering-ssr
I have tried to find any working example online as well or on Next JS website, couldn't find any who has successfully used this configuration with getServerSideProps.
Please help on resolving this and provide a working example of stale-while-revalidate with getServerSideProps.
Provide environment information
Which area(s) are affected? (Select all that apply)
Data fetching (gS(S)P, getInitialProps)
Which stage(s) are affected? (Select all that apply)
next start (local)
Additional context
Tried this with Next js v12 and Next js v13.5.6 , no luck.