mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
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:
@ -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()
|
||||
|
||||
@ -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)
|
||||
|
||||
Reference in New Issue
Block a user