Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/vue-query/src/__tests__/vueQueryPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { isVue2, isVue3, ref } from 'vue-demi'
import { environmentManager } from '@tanstack/query-core'
import { queryKey } from '@tanstack/query-test-utils'
import { QueryClient } from '../queryClient'
import { VueQueryPlugin } from '../vueQueryPlugin'
Expand Down Expand Up @@ -194,6 +195,21 @@ describe('VueQueryPlugin', () => {
})

describe('when called with custom client', () => {
it('should not call mount when running on server', () => {
const appMock = getAppMock()
const customClient = { mount: vi.fn() } as unknown as QueryClient
const previousIsServer = environmentManager.isServer()

environmentManager.setIsServer(() => true)

try {
VueQueryPlugin.install(appMock, { queryClient: customClient })
expect(customClient.mount).toHaveBeenCalledTimes(0)
} finally {
environmentManager.setIsServer(() => previousIsServer)
}
})

itIf(isVue2)('should provide that custom client', () => {
const appMock = getAppMock()
const customClient = { mount: vi.fn() } as unknown as QueryClient
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-query/src/vueQueryPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isVue2 } from 'vue-demi'
import { isServer } from '@tanstack/query-core'
import { environmentManager } from '@tanstack/query-core'

import { QueryClient } from './queryClient'
import { getClientKey } from './utils'
Expand Down Expand Up @@ -38,7 +38,7 @@ export const VueQueryPlugin = {
client = new QueryClient(clientConfig)
}

if (!isServer) {
if (!environmentManager.isServer()) {
client.mount()
}

Expand Down