`useFetch` data return null with mismatching client/request options
See original GitHub issueEnvironment
------------------------------
- Operating System: `Linux`
- Node Version: `v16.14.2`
- Nuxt Version: `3.0.0-27480123.4c77c88`
- Package Manager: `yarn@1.22.18`
- Builder: `vite`
- User Config: `-`
- Runtime Modules: `-`
- Build Modules: `-`
------------------------------
Reproduction
In clean Nuxt project:
<template>
<div>
<NuxtWelcome />
</div>
</template>
<script lang="ts" setup>
const [{ data: organization }, { data: repos }] = await Promise.all([
useFetch(`https://api.github.com/orgs/nuxt`),
useFetch(`https://api.github.com/orgs/nuxt/repos`)
])
console.log(organization.value) // null
const { data: organization } = await useFetch(`https://api.github.com/orgs/nuxt`)
console.log(organization.value) // null
</script>
Describe the bug
useFetch started returning null to the “data” property
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:23 (20 by maintainers)
Top Results From Across the Web
Nuxt 3 useFetch sometimes returns null - Stack Overflow
If an error occurred while fetching (e.g. timeout), data will be null . You can either handle this in your template: <div v-if="data"> ......
Read more >useFetch
Options ; data, Allows you to set a default value for data, undefined ; interceptors.request, Allows you to do something before an http...
Read more >Fetch Standard
A request has an associated reserved client (null, an environment, or an environment settings object). Unless stated otherwise it is null.
Read more >Server configuration - FilePond - PQINA
Asynchronously uploading files with FilePond is called processing. In short, FilePond sends a file to the server and expects the server to return...
Read more >10. Node.js: HTTP, HTTPS - Books at mixu.net
Server request Methods setEncoding(encoding=null) pause() resume() Events data end ... this will print out all the different properties of the current HTTP ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For giving manual key and baseURL to useFetch: (notice
baseURL
case)This will make keys same.
Interesting find @danielroe!
I would still assume it is a bug that the client-side is returning
null
instead of re-attempt to fetch!It is not safe to remove
baseURL
or any other option from auto key generation. Two instances ofuseFetch
with different baseURL will conflict this way.Thinking about some possible improvements. Supporting proxy for me seems best approach. In the meantime, we should improve documentation and warn about this that if URL or options between client/server are not same,
useFetch
needs explicit key or will need to refetch (currently mismatch)Ah. I’ve just seen what you’re doing with baseURL. The key is based on the URL so by changing the URL between server and client, there is a mismatch.
In your case, you could use useAsyncData and pick a key manually.