Struggling with useAsyncData, unexpected api calls
Hello! I’m using
useAsyncData()
to fetch data from Sanity. Whenever I navigate to a page where I’m fetching the data, I see a network request to Sanity. I was under the impression that useAsyncData
would return a static payload and not fire requests to the upstream service. Am I using it wrong?
I’m deploying to Cloudflare Workers. Maybe I missed a step to get things to work as I expected.
Thanks for any help!4 Replies
if you use
generate
or enable payload extraction manually, the calls will be static
otherwise not 🙂I am trying with
generate
and the payload works if I reload from a specific page, no API call happens. but when I try to navigate to a page, it still calls the API. If I call useAsyncData
with the same key on every [slug].vue
page, and reload, then navigate, no API call happens. However, if I start from the homepage and navigate, the API calls happen on every page navigation.
Its really strange.
Here's a deployment if you want to check it out: https://grace-foursquare.pages.dev/Then maybe not all pages are perendered properly?
Hmm…the build process says they are. I wonder if there is a bug in
useSanity
. I’ll try proxying with a server route and see if that resolves it.