Open curiousercreative opened 1 year ago
hey @curiousercreative maybe you are trying to achieve CSR.
When we use Link
component to navigate from one page to another like from home -> /0 or from /0 -> home it will make a network request not matter what you do as it cannot cache route response.
if you want to just change the content based on params
then maybe shallow-routing can help but it only works for page with same url and different query params.
@Rishab49 it seems that routes are cached except when dynamic. Thanks for the link to CSR. I'll give that a shot, seems like it would work for my use case.
@Rishab49 circling back, the App router doesn't support shallow routing it appears.
Link to the code that reproduces this issue
https://github.com/CommonEnergy/nextjs-dynamic-route-segment-client
To Reproduce
npm run build
npm start
Current vs. Expected behavior
Expected result in build: All pages should be built SSG Actual result in build: dynamic route segment is built as SSR
Expected result in browser: dynamic route segment is fetched once Actual result in browser: dynamic route segment is fetched three times (once per dynamic route navigated)
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
App Router, Data fetching (gS(S)P, getInitialProps), Middleware / Edge (API routes, runtime)
Additional context
Deployed to Vercel here: https://nextjs-dynamic-route-segment-client.vercel.app/
Discovered this because the dynamic route segment pages in our app can take as longs as 2 seconds to load (deployed to Vercel, likely cold lambdas). Using the edge runtime with
export const runtime = 'edge'
dramatically reduces the response time, but you can see that it still requires network activity to load a dynamic segment despite being a client component without any server-side data fetching.