Skip to content

Commit

Permalink
fix(useSubscription): don't start on server
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Dec 2, 2019
1 parent 5d3b7dc commit 4c72ff2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/vue-apollo-composable/src/useSubscription.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DocumentNode } from 'graphql'
import Vue from 'vue'
import { Ref, ref, watch, isRef, onUnmounted, computed } from '@vue/composition-api'
import { Ref, ref, watch, isRef, onUnmounted, computed, getCurrentInstance } from '@vue/composition-api'
import { OperationVariables, SubscriptionOptions } from 'apollo-client'
import { Observable, Subscription } from 'apollo-client/util/Observable'
import { FetchResult } from 'apollo-link'
Expand Down Expand Up @@ -30,6 +30,10 @@ export function useSubscription <
variables: TVariables | Ref<TVariables> | ReactiveFunction<TVariables> = null,
options: UseSubscriptionOptions<TResult, TVariables> | Ref<UseSubscriptionOptions<TResult, TVariables>> | ReactiveFunction<UseSubscriptionOptions<TResult, TVariables>> = null
) {
// Is on server?
const vm = getCurrentInstance()
const isServer = vm.$isServer

if (variables == null) variables = ref()
if (!options) options = {}
const documentRef = paramToRef(document)
Expand All @@ -52,7 +56,7 @@ export function useSubscription <
let started = false

function start () {
if (started || !isEnabled.value) return
if (started || !isEnabled.value || isServer) return
started = true
loading.value = true

Expand Down

0 comments on commit 4c72ff2

Please sign in to comment.