refactor(web): extract isServer/isClient utility & upgrade Node.js to 22.12.0 (#30803)

Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com>
This commit is contained in:
yyh
2026-01-12 12:57:43 +08:00
committed by GitHub
parent f9a21b56ab
commit 9161936f41
14 changed files with 40 additions and 20 deletions

View File

@ -12,6 +12,13 @@ import {
usePricingModal,
} from './use-query-params'
// Mock isServer to allow runtime control in tests
const mockIsServer = vi.hoisted(() => ({ value: false }))
vi.mock('@/utils/client', () => ({
get isServer() { return mockIsServer.value },
get isClient() { return !mockIsServer.value },
}))
const renderWithAdapter = <T,>(hook: () => T, searchParams = '') => {
const onUrlUpdate = vi.fn<(event: UrlUpdateEvent) => void>()
const wrapper = ({ children }: { children: ReactNode }) => (
@ -428,6 +435,7 @@ describe('clearQueryParams', () => {
afterEach(() => {
vi.unstubAllGlobals()
mockIsServer.value = false
})
it('should remove a single key when provided one key', () => {
@ -463,13 +471,13 @@ describe('clearQueryParams', () => {
replaceSpy.mockRestore()
})
it('should no-op when window is undefined', () => {
it('should no-op when running on server', () => {
// Arrange
const replaceSpy = vi.spyOn(window.history, 'replaceState')
vi.stubGlobal('window', undefined)
mockIsServer.value = true
// Act
expect(() => clearQueryParams('foo')).not.toThrow()
clearQueryParams('foo')
// Assert
expect(replaceSpy).not.toHaveBeenCalled()

View File

@ -21,6 +21,7 @@ import {
} from 'nuqs'
import { useCallback } from 'react'
import { ACCOUNT_SETTING_MODAL_ACTION } from '@/app/components/header/account-setting/constants'
import { isServer } from '@/utils/client'
/**
* Modal State Query Parameters
@ -176,7 +177,7 @@ export function usePluginInstallation() {
* clearQueryParams(['param1', 'param2'])
*/
export function clearQueryParams(keys: string | string[]) {
if (typeof window === 'undefined')
if (isServer)
return
const url = new URL(window.location.href)