Next.js Discord

Discord Forum

Pages Router - SSR inconsistent

Unanswered
Sloth bear posted this in #help-forum
Open in Discord
Sloth bearOP
In one of our pages, SSR is inconsistent in development, but works exactly as expected in production.

export async function getServerSideProps(context: GetServerSidePropsContext) {
  return renderWithQueriesCached(context, {
    queries: [
      { query: UserDocument, variables: { username: context.query.username } },
      {
        query: PostsDocument,
        variables: { username: context.query.username       } }
      }
    ]
  })
}


In dev, when switching profiles, /user/{name}, the page includes the previous profile's post data + the new profile's post data, however a refresh of the page fixes it properly;

This behavior doesn't occur in prod and works as expected.

21 Replies

Pteromalid wasp
It is occured by enabled cash.
In dev mode, please disable it.
@Pteromalid wasp It is occured by enabled cash. In dev mode, please disable it.
Sloth bearOP
dev enables caching? wouldn't that also be enabled in prod then too lol;

the issue only happens on one dynamic route in particular, the others work completely fine
Pteromalid wasp
Great point
cashing in dev only affects dev behavior
Temporarily disable or adjust caching in dev mode
@Pteromalid wasp Temporarily disable or adjust caching in dev mode
Sloth bearOP
just set a header to disable it and it still occurs, it only happens on this particular dynamic route, other routes work completely fine
Pteromalid wasp
If so, the specific route may be reusing across multi-requests.
Check how caching is managed for that route
@Pteromalid wasp Check how caching is managed for that route
Sloth bearOP
hm I figured it out, it seems as though the query only runs when the page loads initially, any route changing that happens after the initial load doesn't re-trigger SSR
Pteromalid wasp
Yeah, it can be also one reason.
I wonder if my suggestion could be helpful
@Pteromalid wasp Yeah, it can be also one reason. I wonder if my suggestion could be helpful
Sloth bearOP
I did try disabling cache, I think it's maybe related to: https://stackoverflow.com/questions/77071071/page-does-not-refresh-data-even-though-it-uses-no-store-cache-in-next-js-13-4

but that doesn't make sense as to why you'd have to refresh the router given the page is dynamic
Pteromalid wasp
It is needed to ensure that dynamic content updates as expected when navigating between pages.
@Pteromalid wasp It is needed to ensure that dynamic content updates as expected when navigating between pages.
Sloth bearOP
yeah, i'm not sure i'll just keep debugging, I've tried like 4 different solutions so far and neither are working, seems to be an odd case with SSR just not wanting to trigger when the route is pushed with next's link
https://www.joshwcomeau.com/nextjs/refreshing-server-side-props/

seems like this will work, but i don't like the fact this only happens in dev and prod works fine
Pteromalid wasp
Sometimes, I've faced your case, I use forceRefresh or inspecting the service worker
But that link might be helpful for you
Sloth bearOP
yeah, makes sense, curious if anyone else has any input as well 🙂
Pteromalid wasp
Where are you from?
😀
@Pteromalid wasp But that link might be helpful for you
Sloth bearOP
hm I actually figured out the issue, turns out in my posts component:

 <Posts
                    showSortOptions
              variableOverrides={{
                      createdByUser: query.username}}
                  />


the query doesn't update when the route changes unless a hard refresh happens
Pteromalid wasp
Where are you from, Brian?