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

useFetch() option immediate = false does't not stop the request from being made immediately #14982

Closed
then3rdman opened this issue Sep 21, 2022 · 1 comment · Fixed by nuxt/framework#7720

Comments

@then3rdman
Copy link

Environment


  • Operating System: Darwin
  • Node Version: v16.17.0
  • Nuxt Version: 3.0.0-rc.11
  • Nitro Version: 0.5.4
  • Package Manager: yarn@1.22.19
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-bpttlb?file=app.vue

Describe the bug

Unless I am missunderstanding something the purpose of the immediate flag to allow the create of the useFecth and then beable to call it at a later time using the execute() function. It would seem that the flag is being complete ignored and the request is being made immediately.

Additional context

No response

Logs

No response

@aesyondu
Copy link

Hmm yes either this is a bug or immediate should be removed from useFetch.

The problem is immediate is being passed to $fetch, but it should be passed to useAsyncData

https://github.com/nuxt/framework/blob/46240a8c142565eab7eef68212afc0a33cd865d2/packages/nuxt/src/app/composables/fetch.ts#L58

const {
    server,
    lazy,
    default: defaultFn,
    transform,
    pick,
    watch,
    initialCache,
    ...fetchOptions
  } = opts

  const _fetchOptions = {
    ...fetchOptions,
    cache: typeof opts.cache === 'boolean' ? undefined : opts.cache
  }

  const _asyncDataOptions: AsyncDataOptions<_ResT, Transform, PickKeys> = {
    server,
    lazy,
    default: defaultFn,
    transform,
    pick,
    initialCache,
    watch: [
      _request,
      ...(watch || [])
    ]
  }

  const asyncData = useAsyncData<_ResT, ErrorT, Transform, PickKeys>(key, () => {
    return $fetch(_request.value, _fetchOptions) as Promise<_ResT>
  }, _asyncDataOptions)

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

Successfully merging a pull request may close this issue.

3 participants