-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
SWR (and ISR) not working locally #28212
Comments
In order for |
Thanks a lot, that made it work!
|
Environment
Reproduction
Github repo: https://github.com/AdrianFahrbach/nuxt-swr-test
I tested with this repo by following these steps:
npm install
npm run build
npm run preview
http://localhost:3000/page-1
to test the SWR behaviourDescribe the bug
SWR and ISR doesn't seem to work when testing the build locally. Whatevery I try the pages are either completely static or regular SSR on each load.
My testing setup
In my test repository I got three pages (
/page-1
,/page-2
and/page-3
) that all are set as swr pages with a lifespan of 10 seconds. My nuxt config basically looks like this:All of those routes are catched (and validated) in
pages/[...slug].vue
. This component also gets a current timestamp from an external API usingfetch
in anuseAsyncStorage
hook. That looks like this:The response of that call includes a timestamp which gets displayed on the page. In addition to that I also calculate the seconds from now to the timestamp retrieved during SSR. My full component basically looks like this:
To test SWR I build the app using
nuxt build
and preview it usingnuxt preview
.Expected behaviour
When previewing my application I expect it to behave (as close as possible) as it would in an production environment. In this case I expect the timestamp to change every 10 seconds, since my pages should get stale after 10 seconds and then refresh the server side data fetch from
useAsyncData
.useAsyncData
should also only be running on the server similar to Next.jsgetStaticProps
orgetServerSideProps
.Current behaviour
When opening the pages the timestamp doesn't change but instead always stays the same as it was during build.
Additional context
#18787 Static and SWR rendering not working
This issue has a discussion about a similar problem, however the suggested solutions here didn't help me and there is no mention of local testing.
#9474 SSR asyncData issue: rendering on client instead of server
#27840 nuxtlink or navigateto forces client side request instead of SSR
On a different project it got SWR without revalidation working (so basically static). The problem there was that
useAsyncData
was then running on the client when navigating with a Nuxt link. I'm not quite sure if this is intentional, since I personally wouldn't expectuseAsyncData
to run on the client and therefore this may be related to this.The text was updated successfully, but these errors were encountered: