Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

fix: useFetch fails inside onGlobalSetup callback #275

Closed
logaretm opened this issue Oct 19, 2020 · 0 comments
Closed

fix: useFetch fails inside onGlobalSetup callback #275

logaretm opened this issue Oct 19, 2020 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@logaretm
Copy link

logaretm commented Oct 19, 2020

🐛 The bug

Similar to #264 now I'm running into an issue where a useFetch doesn't work inside onGlobalSetup callback, it fails because of null access to some properties on the vm

My use case is that I read some cookies from the req object and use fetch to pre-load some user-related data for SSR rendering.

Here is a snippet:

import { onGlobalSetup, useFetch } from "@nuxtjs/composition-api";

export default function () {
  onGlobalSetup(() => {
    useFetch(() => {
     // ...
    });
  });
}

No need to do any fetching logic, just calling useFetch inside onGlobalSetup callback is enough to trigger the error

🛠️ To reproduce

  1. Create a setup.js plugin file and add it to nuxt.config.js
  2. Use the following snippet:
import { onGlobalSetup, useFetch } from "@nuxtjs/composition-api";

export default function () {
  onGlobalSetup(() => {
    useFetch(() => {
     // ...
    });
  });
}
  1. Reload the page

Reproduction link:

https://codesandbox.io/s/hungry-torvalds-7nt86?file=/plugins/setup.js:0-182

🌈 Expected behaviour

useFetch should work inside onGlobalSetup, or if intended then it should be reflected in the documentation.

ℹ️ Additional context

I'm working on a fix for this at the moment that works fine on my project, will send a PR once done!

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

Successfully merging a pull request may close this issue.

2 participants