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

useAsyncData return value that pending is true at server side when server: false #15714

Closed
Mini-ghost opened this issue Dec 3, 2022 · 8 comments

Comments

@Mini-ghost
Copy link
Contributor

Environment


  • Operating System: Linux
  • Node Version: v16.14.2
  • Nuxt Version: 3.0.0
  • Nitro Version: 1.0.0
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-qorbrt?file=app.vue

Open DevTool, <NuxtWelcome /> not render at server side.

Describe the bug

When we use useAsyncData() and set server: false. the return value pending will get true at server side. It should be false? because this will not invoke at server side.

Additional context

No response

Logs

No response

@Mini-ghost Mini-ghost changed the title Component not render on server side when useAsyncData is server: false useAsyncData return value that pending is true as server side when server: false Dec 3, 2022
@Mini-ghost Mini-ghost changed the title useAsyncData return value that pending is true as server side when server: false useAsyncData return value that pending is true at server side when server: false Dec 3, 2022
@manniL
Copy link
Member

manniL commented Dec 3, 2022

I see your point here. But: Usually, pending is used to e.g. provide placeholders or default content while the data is not there yet. As the data isn't there, pending is set to true. ☺️

Curious for suggestions/feedback

@mahdiboomeri
Copy link
Contributor

My suggestion is a new fetching property. It should be true only when the handler's promise is pending.

I've been exploring this idea in a module I'm working on, you can check it out in nuxt-query.

@Mini-ghost
Copy link
Contributor Author

@manniL

Thank you for your answer, I think I misunderstood the meaning of pending.

But in documentation, the useAsyncData mentions that:
https://github.com/nuxt/framework/blob/dd56d36e3ea012d635daf22677086b8218f6e089/docs/content/1.docs/3.api/1.composables/use-async-data.md?plain=1#L64

According to the description here, I think the meaning is closer to fetching mentioned by @mahdiboomeri. Should we adjust the description of this property in the documentation?

@DamianGlowala
Copy link
Member

I find the initial value of pending set to true confusing whenever I have the immediate: false.

@danielroe, would you consider it to be a bug? Should the immediate option impact the initial value of pending?

@feelixe
Copy link

feelixe commented Dec 6, 2022

I also interpreted pending as meaning "loading" initially.

Let's say you want to display a loading spinner while the handler is being executed with immediate: false. You obviously don't want that spinner to be visible before the handler has been called, which will be the case if you condition the rendering of the spinner on pending.

Right now, there is no way to determine if the handler of the useAsyncData hook is loading. I tried achieving this with some wrapper around it, but I could think of nothing that wouldn't require changing the source of the original hook.

If the pending property is indeed working as the authors intended, then I think it should not be changed. But then I believe it would be useful to have a loading property that tells us if the handler function is being pending.

@sakhshijan
Copy link

sakhshijan commented Jan 18, 2023

i had same issue and the only thing i did it is this

const {  data,  pending,  error,  refresh} = await useAsyncData(() => test(), {immediate: false});
pending.value = false;

in setup script. and it works!

@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe transferred this issue from nuxt/framework Jan 19, 2023
@Quineone
Copy link

Quineone commented Feb 6, 2023

My suggestion is a new fetching property. It should be true only when the handler's promise is pending.

I've been exploring this idea in a module I'm working on, you can check it out in nuxt-query.

Yes, indeed, I agree. pending is more like whether the data is fetched complete or not. act as the
vueuse useAsyncState isReady did , so we also need the isLoading property, @danielroe what do you think?
Or we can fix the pending is false when the immediate is false?

@manniL
Copy link
Member

manniL commented Feb 6, 2023

We decided to introduce a status property for more fine-grained control as pending is a mix-up of a few statuses here as discussed.

Closing this discussion here 👍🏻
Thanks everyone for your input

Follow-up on #18810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants