nuxt-full-static icon indicating copy to clipboard operation
nuxt-full-static copied to clipboard

fix: Double requests being made on client-side

Open simoneldevig opened this issue 3 years ago â€ĸ 5 comments

🐛 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 🙂

Screenshot 2022-09-04 at 19 17 42

â„šī¸ Additional context

No response

simoneldevig avatar Sep 04 '22 17:09 simoneldevig

Would you provide some more info? I can't reproduce this.

danielroe avatar Sep 07 '22 21:09 danielroe

@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 😄

simoneldevig avatar Sep 08 '22 08:09 simoneldevig

The router should await all work in the prefetch function. I'll wait your findings 👍

danielroe avatar Sep 08 '22 08:09 danielroe

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?

TechAkayy avatar Sep 10 '22 13:09 TechAkayy

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.

TechAkayy avatar Sep 12 '22 07:09 TechAkayy