Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nuxt3] Async data called twice #44

Closed
benjamincanac opened this issue Feb 9, 2022 — with Volta.net · 15 comments
Closed

[Nuxt3] Async data called twice #44

benjamincanac opened this issue Feb 9, 2022 — with Volta.net · 15 comments
Labels
bug Something isn't working

Comments

Copy link
Member

benjamincanac commented Feb 9, 2022

When using useAsyncData, the http call is made on server and on client.

@benjamincanac benjamincanac added the bug Something isn't working label Feb 9, 2022 — with Volta.net
@benjamincanac benjamincanac changed the title Create reproduction test with nuxt3 starter for double async data call [Nuxt3] Create reproduction with starter for double async data call Feb 9, 2022
@benjamincanac benjamincanac changed the title [Nuxt3] Create reproduction with starter for double async data call [Nuxt3] Create reproduction for double async data call Feb 9, 2022
Copy link
Member Author

nuxt/nuxt#13366

@benjamincanac benjamincanac changed the title [Nuxt3] Create reproduction for double async data call [Nuxt3] Async data called twice Feb 21, 2022
Copy link
Contributor

Tahul commented Feb 22, 2022

nuxt/nuxt#13369

Can be tracked here now; I also added another a reproduction

Copy link
Member

Atinux commented Mar 8, 2022

Related to vuejs/core#5513

@danielroe
Copy link
Member

danielroe commented Mar 15, 2022

This should be fixed in latest Nuxt. However, you may notice that setup is still running twice (as this is caused by upstream bug) linked by @Atinux. If you encounter this, you can work around for now by enabling keepalive on the parent:

<script setup>
definePageMeta({
  keepalive: true
})
</script>

Copy link
Member Author

@danielroe Just tried the latest version of nuxt, the useAsyncData is now called once for non-child page. I still have the second call on the client-side for all children.

@danielroe
Copy link
Member

danielroe commented Mar 15, 2022

Yes, that would be the upstream bug. Have you tried with the workaround I mentioned? If it doesn't work, I can see if I can find another workaround for you.

Copy link
Member Author

I did try to add the keepalive prop but it didn't change a thing, do I have to put it in all the parents all the way through app.vue?

@danielroe
Copy link
Member

It only works in pages, and it only needs to be set in the parent page which has a child with setup() running twice. If that doesn't work, if you could point me to a reproduction, that would be helpful.

Copy link
Member Author

Do you have nuxt.com running?

@danielroe
Copy link
Member

I have access to the repo but it's not setup with env variables or backend.

Copy link
Member Author

Would you rather have the full .env so you could run the API with docker or have a reproduction link with Stackblitz for example?

@danielroe
Copy link
Member

I can reproduce the issue, but can resolve it with my workaround above.

I need to see why it's not working for Nuxt.com specifically.

If you can repro it not working in stackblitz even with my workaround, that would be ideal. Otherwise, the full .env would be perfect.

Copy link
Member Author

An easier way would be to clone nuxt.com on your local, set the STRAPI_URL env variable to https://dev-api.nuxt.com and copy your cookie strapi_jwt from https://dev.nuxt.com to your http://localhost:3000.

@danielroe
Copy link
Member

Sounds good 👍 How can I reproduce the issue then?

Copy link
Member Author

Awesome! You can go to http://localhost:3000/@danielroe/projects and see that the /projects http call is made on client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants