From 9807a7b4540b1698a6e6b5852395e24ebd3fb0f2 Mon Sep 17 00:00:00 2001 From: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com> Date: Sat, 30 May 2026 14:55:27 +0530 Subject: [PATCH] fix(vue-query): use environmentManager.isServer in plugin --- .../src/__tests__/vueQueryPlugin.test.ts | 16 ++++++++++++++++ packages/vue-query/src/vueQueryPlugin.ts | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/vue-query/src/__tests__/vueQueryPlugin.test.ts b/packages/vue-query/src/__tests__/vueQueryPlugin.test.ts index cfcb18ce956..3b073e5ac67 100644 --- a/packages/vue-query/src/__tests__/vueQueryPlugin.test.ts +++ b/packages/vue-query/src/__tests__/vueQueryPlugin.test.ts @@ -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' @@ -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 diff --git a/packages/vue-query/src/vueQueryPlugin.ts b/packages/vue-query/src/vueQueryPlugin.ts index 590d994d304..5c24bac18b7 100644 --- a/packages/vue-query/src/vueQueryPlugin.ts +++ b/packages/vue-query/src/vueQueryPlugin.ts @@ -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' @@ -38,7 +38,7 @@ export const VueQueryPlugin = { client = new QueryClient(clientConfig) } - if (!isServer) { + if (!environmentManager.isServer()) { client.mount() }