Skip to content

onServerPrefetch does not exist in Vue 3 #1042

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

Closed
reegodev opened this issue Aug 12, 2020 · 2 comments
Closed

onServerPrefetch does not exist in Vue 3 #1042

reegodev opened this issue Aug 12, 2020 · 2 comments
Labels

Comments

@reegodev
Copy link

Describe the bug
The onServerPrefetch lifecycle hook does not exist anymore in Vue 3

To Reproduce
Steps to reproduce the behavior:

  1. Setup a Vue 3 project
  2. Install Vue Apollo
  3. Install @vue/apollo-composable
  4. Perform a query using useQuery
  5. In console you should see the error TypeError: vue_demi_1.onServerPrefetch is not a function

Versions
vue: 3
vue-apollo: 4.0.0-alpha.10
apollo-client: 2.6.10

@parion
Copy link

parion commented Sep 7, 2020

While some outstanding patch PRs are awaiting fixes and reviews, the following patch should help:
#1011 (comment)

@Akryum Akryum added the v4 label Oct 15, 2020
@Akryum Akryum changed the title v4: onServerPrefetch does not exist in Vue 3 onServerPrefetch does not exist in Vue 3 Oct 15, 2020
@wobsoriano
Copy link

Works now

<script setup lang="ts">
import { onServerPrefetch, ref } from 'vue'

const todo = ref()

onServerPrefetch(async() => {
  const resp = await fetch('https://jsonplaceholder.typicode.com/todos/1')
  const data = await resp.json()
  todo.value = data
})
</script>

@Akryum Akryum closed this as completed Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants