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

fix: UseFetch in 0.24.0 #455

Closed
gisu opened this issue Apr 14, 2021 · 4 comments
Closed

fix: UseFetch in 0.24.0 #455

gisu opened this issue Apr 14, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@gisu
Copy link

gisu commented Apr 14, 2021

In my current project, useFetch is not behaving properly. I retrieve data with the Fetch API, the function is swapped to a separate file.

export default function () {
  const { store, $apiClient } = useContext()
  const projectData = computed(() => $store.getters['projects/getProjects'])
  const userId = computed(() => $store.getters['access/getUserId'])
  const projects = ref(null)
  useFetch(async () => {
    try {
      const scoreRepo = await $apiClient.getRepository('score')
      const { scores } = await scoreRepo.getScoresByUser(userId.value, {
        scores: [ 'basic-uptime'],
      })
      projects.value = mapProjects(scores, projectData)
    } catch (error) {
      console.error(error)
    }
  })

  return {
    projects
  }
}

Within the component then the call of the function

setup () {
    const { projects } = getProject()
    return { projects }
  },

In 0.22.x, I could query $fetchState.pending in the template, if the state was set to false, the results were displayed to me. When manually reloading the page as well as when the router calls the page. In 0.23.x the $fetchState.pending stays on true. Only when I change something in the code in the dev task, the state changes.

In the external function I can get the fetchState, which also changes correctly.
When I build the app the pending state also stays on true. what do i have to do differently? Because downgrade to 0.22.x is also not a solution in the long run.

** To reproduce**
Following my test package. Curiously it is the other way around, as long as the dev task is running and Hotreload injects new code, the fetch state does not change. It stays on Pending until you execute Reload.

My actual app is much bigger and contains more plugins than the test project. But as I said with 0.22.3 it works without problems. With 0.24.0 the fetchState never changes on reload.

https://github.com/gisu/nuxt-composition-api-test

Expected behaviour
That the $fetchState.pending state is set to false as soon as the requests have been completed, both for route changes and for manual page reloads.

@gisu gisu added the bug Something isn't working label Apr 14, 2021
@impowski
Copy link

Same thing for me $fetchState.pending is always true

@danielroe
Copy link
Member

Hopefully this should be fixed in v0.23.1. Let me know if it resolves the issue for you.

@danielroe danielroe reopened this Apr 14, 2021
@impowski
Copy link

@danielroe works fine, thanks :)

Copy link
Member

@impowski Great - glad to hear it 😊

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

No branches or pull requests

3 participants