Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initialData has different behaviour on SSR compared to CSR #275

Closed
feclist opened this issue Feb 21, 2020 · 2 comments
Closed

initialData has different behaviour on SSR compared to CSR #275

feclist opened this issue Feb 21, 2020 · 2 comments

Comments

@feclist
Copy link

feclist commented Feb 21, 2020

Hi all,

We're working on an app that has pages load either CSR or SSR using Next.js. I noticed that when I provide initialData to my useSWR hook and it's SSRed it works all fine. Now if the user is navigated to the same page through CSR and initialData is provided it ignores the initialData and uses the cache instead. I assume that this initialData should have consistent behaviour for both SSR and CSR, or am I wrong to assume that?

I haven't tried manually mutating the object such that it revalidates. I did check that, when I remove the initialData field it seems to work fine. Not completely sure how solid that solution is.

It'd be great to get some feedback on this!

Cheers

@feclist
Copy link
Author

feclist commented Feb 21, 2020

Having thought about it for a bit, they don’t behave different at all.. Our use case gets a ‘fresh’ CSR page that should be filled with ‘fresh’ SWR data. Now, commonly client-side the cache should hold the most recent version, whereas we have an ‘empty’ page.

On CSR it’s likely that it already had responses, those should be preferred over initialData.

There’s two ways I can go about this now:

  1. Clear the cache somehow and have swr refetch by itself;
  2. Figure out some logic on which I can call trigger to refresh the data;
  3. A more graceful option?

Would there be a better way than point 1 or 2?

@huozhi
Copy link
Member

huozhi commented Jun 28, 2021

@feclist could you try the solution posted in #284 (comment) ?
Will close this issue as it seems to be reoslved with swr@beta, feel free to comment or reopen if you have any further issues

@huozhi huozhi closed this as completed Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants