The fetch() hook is no longer called on the client-side in production/universal mode
See original GitHub issueHey!
First of all thanks for the nice work 😃
I encountered something really strange and I’m not too sure about it but it looks like that the new fetch()
hook of nuxt is not called on the client-side when in production mode:
Version
@nuxt/content: ^1.6.0 nuxt: 2.14.0
Steps to reproduce
Create a dynamic page component with a fetch()
hook (example: pages/projects/_slug.vue).
export default {
fetch() {
console.log('fetch');
}
}
What is Expected?
Fetch to be called when navigation occurs and a project is shown on the client side.
What is actually happening?
Fetch is only called on the client side when in development mode. In production mode, it is never called (only on the server).
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:16 (5 by maintainers)
Top Results From Across the Web
The Fetch Hook - Nuxt
The fetch hook is for fetching data asynchronously. It is called on server-side when rendering the route, and on client-side when navigating.
Read more >Difference between Asyncdata vs Fetch - vue.js - Stack Overflow
The fetch method is used to fill the store before rendering the page, it's like the asyncData method except it doesn't set the...
Read more >NextJS / React SSR: 21 Universal Data Fetching Patterns ...
What's special about this hook? You're free to put React Component anywhere in your application. By default, it will server-render the first ...
Read more >Firebase JavaScript SDK Release Notes - Google
Introduce client-side indexing with beta API setIndexConfiguration() . ... When issued for queries that are being listened to, get() calls no longer send ......
Read more >Creating Server-side Rendered Vue.js Apps Using Nuxt.js
This is a big indication that something is wrong with the application logic. Thankfully, an error will be generated in your browser's console...
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
After stepping through production code, I found the issue (for me at least) is not that fetch isn’t called. It’s that the component’s
fetchKey
is misaligned with the cached fetch data ($nuxt._pagePayload.fetch
). After setting a customfetchKey
(thanks to #8466), the issue went away.If this is indeed the correct solution, the documentation should give some guidance on when to use the new
fetchKey
optionwhen using Nuxt Content.If the content would show up on client-side navigation, I would agree with you. Since it doesn’t we have to call
$fetch()
by hand again.We use a component in
pages/index.vue
that fetches stories written in *.md-files with Nuxt-content (<slug>-<locale>.md
). Each md-file has yaml vars up top for title, description etc. and locale.$ npm run generate
and$ npm run start
shows the stories on initial load, which makes sense, because the stories are hardcoded intodist/index.html
./
again, the stories are not there.That must mean
fetch()
-hook is not called or the “caching” that Nuxt uses under the hood doesn’t really work with Nuxt-Content.Here is our component:
Maybe I’ll find time to recreate the issue in a sandbox, but for now I hope this information helps getting to the bottom of this.