nuxt-full-static
nuxt-full-static copied to clipboard
fix: Double requests being made on client-side
đ The bug
After some testing of the module it looks like that it's actually doing two requests per page on the client-side. One for the static json file and one for the actual API.
I've tried the example from the docs with adding a process.server check to my useAsyncData but that just returns false.
đ ī¸ To reproduce
https://stackblitz.com/github/danielroe/nuxt-full-static/tree/main/playground
đ Expected behaviour
When click on the individual posts I would expect it to only make a request for the static json file but it also makes a request to the API đ
âšī¸ Additional context
No response
Would you provide some more info? I can't reproduce this.
@danielroe hmm - me neither.
Unfortunately I'm not able to create a proper reproduction of what happens in my own project, since it's currently running with a local api.
I suspect that it might be caused by a timing issue with the Object.assign and big amounts of data in the client plugin, which might cause the route to resolved before the data is added to the payload cache.
I'll try to do some testing with wrapping it in a promise and manually resolving once data has been mapped and make a PR if I find a solution đ
The router should await all work in the prefetch function. I'll wait your findings đ
Hi Daniel, I see api calls made from client-side as well. Here is a screen recording. Repo here - https://stackblitz.com/github/TechAkayy/danielroe-nuxt-full-static?file=nuxt.config.ts
I referred to Sebastian's video here https://www.nuxtjs.cn/blog/going-full-static as a reference. So, if I'm not wrong, the payload.js should show up in my devtools sources & there shouldn't be any api calls at all with full-static. Does your cover both stubbing as well as payload extraction?
https://user-images.githubusercontent.com/73772701/189486227-cdf8e07f-1748-41bc-acd0-49986b4ce86d.mov
Also, is the "build" command with setting nitro.prerender.crawlLinks:true the same as "generate" command? If not, when is nitro.prerender.crawlLinks is required when we want to generate a full static site?
Also, in the above repo, from the posts.vue page, clicking on the various post titles, it opens the same post.
If post with id:10 is clicked first, then going back to all posts and clicking a different title, opens post id:10 again.