diff --git a/apps/web/src/components/ui/photo-viewer/animations/usePhotoViewerTransitions.ts b/apps/web/src/components/ui/photo-viewer/animations/usePhotoViewerTransitions.ts index 81101fdd..4ebeebf4 100644 --- a/apps/web/src/components/ui/photo-viewer/animations/usePhotoViewerTransitions.ts +++ b/apps/web/src/components/ui/photo-viewer/animations/usePhotoViewerTransitions.ts @@ -118,11 +118,6 @@ export const usePhotoViewerTransitions = ({ if (!isOpen || !currentPhoto) return if (entryTransition || isViewerContentVisible) return - if (typeof window === 'undefined') { - setIsViewerContentVisible(true) - return - } - const triggerEl = resolveTriggerElement() if (!triggerEl) { @@ -208,12 +203,6 @@ export const usePhotoViewerTransitions = ({ return } - if (typeof window === 'undefined') { - wasOpenRef.current = false - restoreTriggerElementVisibility() - return - } - const triggerEl = resolveTriggerElement() if (!triggerEl || !triggerEl.isConnected) { diff --git a/apps/web/src/components/ui/photo-viewer/animations/utils.ts b/apps/web/src/components/ui/photo-viewer/animations/utils.ts index 388c5719..858ba8ba 100644 --- a/apps/web/src/components/ui/photo-viewer/animations/utils.ts +++ b/apps/web/src/components/ui/photo-viewer/animations/utils.ts @@ -15,7 +15,7 @@ const THUMBNAIL_PADDING = { } as const export const escapeAttributeValue = (value: string) => { - if (typeof window !== 'undefined' && window.CSS?.escape) { + if (window.CSS?.escape) { return window.CSS.escape(value) } @@ -23,14 +23,13 @@ export const escapeAttributeValue = (value: string) => { } const getRootFontSize = () => { - if (typeof window === 'undefined') return 16 const value = window.getComputedStyle(document.documentElement).fontSize const parsed = Number.parseFloat(value || '16') return Number.isNaN(parsed) ? 16 : parsed } export const getBorderRadius = (element: Element | null) => { - if (typeof window === 'undefined' || !element) return 0 + if (!element) return 0 const computedStyle = window.getComputedStyle(element) const radiusCandidates = [ diff --git a/apps/web/src/config/index.ts b/apps/web/src/config/index.ts index ebfd3beb..e19d2bf1 100644 --- a/apps/web/src/config/index.ts +++ b/apps/web/src/config/index.ts @@ -11,7 +11,7 @@ const defaultInjectConfig = { export const injectConfig = merge(defaultInjectConfig, __CONFIG__) const getInjectedSiteConfig = (): Partial | undefined => { - if (typeof window !== 'undefined' && window.__SITE_CONFIG__) { + if (window.__SITE_CONFIG__) { return window.__SITE_CONFIG__ } diff --git a/apps/web/src/lib/device-viewport.ts b/apps/web/src/lib/device-viewport.ts index 40a852d6..36977692 100644 --- a/apps/web/src/lib/device-viewport.ts +++ b/apps/web/src/lib/device-viewport.ts @@ -1,7 +1,6 @@ export const isSafari = /Safari/.test(navigator.userAgent) && !/Chrome/.test(navigator.userAgent) export const isMobileDevice = (() => { - if (typeof window === 'undefined') return false return ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || // 现代检测方式:支持触摸且屏幕较小 diff --git a/be/apps/dashboard/src/components/common/ErrorElement.tsx b/be/apps/dashboard/src/components/common/ErrorElement.tsx index 8cf993af..7dedac78 100644 --- a/be/apps/dashboard/src/components/common/ErrorElement.tsx +++ b/be/apps/dashboard/src/components/common/ErrorElement.tsx @@ -19,21 +19,18 @@ export function ErrorElement() { }, [error]) const reloadTriggeredRef = useRef(false) - const hasWindow = typeof window !== 'undefined' const shouldAttemptReload = - hasWindow && - message.startsWith('Failed to fetch dynamically imported module') && - window.sessionStorage.getItem('reload') !== '1' + message.startsWith('Failed to fetch dynamically imported module') && window.sessionStorage.getItem('reload') !== '1' useEffect(() => { - if (!shouldAttemptReload || reloadTriggeredRef.current || !hasWindow) { + if (!shouldAttemptReload || reloadTriggeredRef.current) { return } reloadTriggeredRef.current = true window.sessionStorage.setItem('reload', '1') window.location.reload() - }, [hasWindow, shouldAttemptReload]) + }, [shouldAttemptReload]) if (shouldAttemptReload) { return null diff --git a/be/apps/dashboard/src/lib/api-client.ts b/be/apps/dashboard/src/lib/api-client.ts index 1ab943b0..46f61a9d 100644 --- a/be/apps/dashboard/src/lib/api-client.ts +++ b/be/apps/dashboard/src/lib/api-client.ts @@ -17,7 +17,7 @@ export const coreApi = $fetch.create({ setAccessDenied({ active: true, status: 403, - path: typeof window !== 'undefined' ? window.location.pathname : current?.path, + path: window.location.pathname, scope: current?.scope ?? 'api', reason: detail, source: 'api', diff --git a/be/apps/dashboard/src/modules/auth/components/SocialAuthButtons.tsx b/be/apps/dashboard/src/modules/auth/components/SocialAuthButtons.tsx index 07a06f09..a43743b3 100644 --- a/be/apps/dashboard/src/modules/auth/components/SocialAuthButtons.tsx +++ b/be/apps/dashboard/src/modules/auth/components/SocialAuthButtons.tsx @@ -33,10 +33,8 @@ export const SocialAuthButtons = memo(function SocialAuthButtons({ if (callbackURL) { return callbackURL } - if (typeof window !== 'undefined') { - return window.location.href - } - return + + return window.location.href }, [callbackURL]) const handleSocialClick = useCallback( diff --git a/be/apps/dashboard/src/modules/auth/components/SocialConnectionSettings.tsx b/be/apps/dashboard/src/modules/auth/components/SocialConnectionSettings.tsx index ea2d8552..e69ddada 100644 --- a/be/apps/dashboard/src/modules/auth/components/SocialConnectionSettings.tsx +++ b/be/apps/dashboard/src/modules/auth/components/SocialConnectionSettings.tsx @@ -46,11 +46,6 @@ export function SocialConnectionSettings() { const handleConnect = useCallback( async (providerId: string, providerName: string) => { - if (typeof window === 'undefined') { - toast.error('当前环境不支持 OAuth 绑定') - return - } - const url = new URL(window.location.href) url.searchParams.set('auth-flow', 'link') url.searchParams.set('provider', providerId) diff --git a/be/apps/dashboard/src/modules/auth/hooks/useLogin.ts b/be/apps/dashboard/src/modules/auth/hooks/useLogin.ts index 3ddc2719..ac3f7218 100644 --- a/be/apps/dashboard/src/modules/auth/hooks/useLogin.ts +++ b/be/apps/dashboard/src/modules/auth/hooks/useLogin.ts @@ -25,7 +25,7 @@ export function useLogin() { const loginMutation = useMutation({ mutationFn: async (data: LoginRequest) => { if (data.requireRootDomain) { - const slug = typeof window !== 'undefined' ? getTenantSlugFromHost(window.location.hostname) : null + const slug = getTenantSlugFromHost(window.location.hostname) if (slug !== 'root') { const rootUrl = buildRootTenantUrl('/root-login') window.location.replace(rootUrl) @@ -56,7 +56,7 @@ export function useLogin() { const isSuperAdmin = session.user.role === 'superadmin' if (tenant && !tenant.isPlaceholder && tenant.slug) { - const currentSlug = typeof window !== 'undefined' ? getTenantSlugFromHost(window.location.hostname) : null + const currentSlug = getTenantSlugFromHost(window.location.hostname) if (!isSuperAdmin && tenant.slug !== currentSlug) { try { const targetUrl = buildTenantUrl(tenant.slug, '/') diff --git a/be/apps/dashboard/src/modules/auth/utils/domain.ts b/be/apps/dashboard/src/modules/auth/utils/domain.ts index 11d1bfdf..22c6063a 100644 --- a/be/apps/dashboard/src/modules/auth/utils/domain.ts +++ b/be/apps/dashboard/src/modules/auth/utils/domain.ts @@ -65,10 +65,6 @@ export function buildTenantUrl(slug: string, path = '/'): string { throw new Error('Workspace slug is required to build tenant URL.') } - if (typeof window === 'undefined') { - throw new TypeError('Cannot build tenant URL outside the browser environment.') - } - const { protocol, hostname, port } = window.location const baseDomain = resolveBaseDomain(hostname) diff --git a/be/apps/dashboard/src/modules/photos/components/PhotoPage.tsx b/be/apps/dashboard/src/modules/photos/components/PhotoPage.tsx index 4f8eeadc..82849e2f 100644 --- a/be/apps/dashboard/src/modules/photos/components/PhotoPage.tsx +++ b/be/apps/dashboard/src/modules/photos/components/PhotoPage.tsx @@ -44,7 +44,6 @@ const STAGE_ORDER: PhotoSyncProgressStage[] = [ ] const MAX_SYNC_LOGS = 200 -const PHOTO_SYNC_RESULT_STORAGE_KEY = 'photo-sync:last-result' function createInitialStages(totals: PhotoSyncProgressState['totals']): PhotoSyncProgressState['stages'] { return STAGE_ORDER.reduce( @@ -73,32 +72,6 @@ export function PhotoPage() { const [resolvingConflictId, setResolvingConflictId] = useState(null) const [syncProgress, setSyncProgress] = useState(null) - useEffect(() => { - if (typeof window === 'undefined') { - return - } - - const restoreStoredResult = () => { - try { - const cached = window.sessionStorage.getItem(PHOTO_SYNC_RESULT_STORAGE_KEY) - if (!cached) { - return - } - - const parsed = JSON.parse(cached) as { result?: PhotoSyncResult; lastWasDryRun?: boolean | null } - if (parsed?.result) { - setResult(parsed.result) - setLastWasDryRun(parsed.lastWasDryRun ?? null) - } - } catch (error) { - console.error('Failed to restore cached photo sync result', error) - window.sessionStorage.removeItem(PHOTO_SYNC_RESULT_STORAGE_KEY) - } - } - - restoreStoredResult() - }, []) - useEffect(() => { setActiveTab(normalizedInitialTab) }, [normalizedInitialTab]) @@ -303,16 +276,7 @@ export function PhotoPage() { setResult(data) setLastWasDryRun(context.dryRun) setSyncProgress(null) - if (typeof window !== 'undefined') { - try { - window.sessionStorage.setItem( - PHOTO_SYNC_RESULT_STORAGE_KEY, - JSON.stringify({ result: data, lastWasDryRun: context.dryRun }), - ) - } catch (error) { - console.error('Failed to persist photo sync result snapshot', error) - } - } + void summaryQuery.refetch() void listQuery.refetch() }, diff --git a/be/apps/dashboard/src/modules/photos/components/sync/PhotoSyncConflictsPanel.tsx b/be/apps/dashboard/src/modules/photos/components/sync/PhotoSyncConflictsPanel.tsx index 38b3deb5..82aa1f98 100644 --- a/be/apps/dashboard/src/modules/photos/components/sync/PhotoSyncConflictsPanel.tsx +++ b/be/apps/dashboard/src/modules/photos/components/sync/PhotoSyncConflictsPanel.tsx @@ -173,10 +173,6 @@ export function PhotoSyncConflictsPanel({ } const confirmAction = (message: string, onConfirm: () => void | Promise) => { - if (typeof window === 'undefined') { - return onConfirm() - } - Prompt.prompt({ title: '确认操作', description: message, diff --git a/be/apps/dashboard/src/modules/welcome/components/tenant-utils.ts b/be/apps/dashboard/src/modules/welcome/components/tenant-utils.ts index 21506230..ab0849e2 100644 --- a/be/apps/dashboard/src/modules/welcome/components/tenant-utils.ts +++ b/be/apps/dashboard/src/modules/welcome/components/tenant-utils.ts @@ -1,7 +1,4 @@ export const getCurrentHostname = (): string | null => { - if (typeof window === 'undefined') { - return null - } try { return window.location.hostname } catch { @@ -10,10 +7,6 @@ export const getCurrentHostname = (): string | null => { } export const buildRegistrationUrl = (): string => { - if (typeof window === 'undefined') { - return '/platform/welcome' - } - try { const { protocol, host } = window.location return `${protocol}//${host}/platform/welcome` @@ -23,10 +16,6 @@ export const buildRegistrationUrl = (): string => { } export const buildHomeUrl = (): string => { - if (typeof window === 'undefined') { - return '/' - } - try { const { protocol, hostname, port } = window.location const normalizedPort = port ? `:${port}` : '' diff --git a/be/apps/dashboard/src/pages/(onboarding)/login.tsx b/be/apps/dashboard/src/pages/(onboarding)/login.tsx index 7f7787f1..f97f3669 100644 --- a/be/apps/dashboard/src/pages/(onboarding)/login.tsx +++ b/be/apps/dashboard/src/pages/(onboarding)/login.tsx @@ -12,9 +12,6 @@ export function Component() { const [password, setPassword] = useState('') const { login, isLoading, error, clearError } = useLogin() const tenantSlug = useMemo(() => { - if (typeof window === 'undefined') { - return null - } return getTenantSlugFromHost(window.location.hostname) }, []) const showEmailLogin = !tenantSlug diff --git a/be/apps/dashboard/src/pages/(onboarding)/root-login.tsx b/be/apps/dashboard/src/pages/(onboarding)/root-login.tsx index cfcd190c..a02d9b3f 100644 --- a/be/apps/dashboard/src/pages/(onboarding)/root-login.tsx +++ b/be/apps/dashboard/src/pages/(onboarding)/root-login.tsx @@ -14,9 +14,6 @@ export function Component() { const { login, isLoading, error, clearError } = useLogin() const tenantSlug = useMemo(() => { - if (typeof window === 'undefined') { - return null - } return getTenantSlugFromHost(window.location.hostname) }, []) const rootLoginHref = useMemo(() => { @@ -33,10 +30,6 @@ export function Component() { return } - if (typeof window === 'undefined') { - return - } - const targetUrl = buildRootTenantUrl('/root-login') if (window.location.href === targetUrl) { return @@ -89,9 +82,7 @@ export function Component() { variant="primary" className="w-full" onClick={() => { - if (typeof window !== 'undefined') { - window.location.href = rootLoginHref - } + window.location.href = rootLoginHref }} > Go to root portal diff --git a/packages/docs/src/App.tsx b/packages/docs/src/App.tsx index 0e36f4ef..818174ef 100644 --- a/packages/docs/src/App.tsx +++ b/packages/docs/src/App.tsx @@ -30,9 +30,8 @@ function App({ url }: { url?: string }) { setCurrentPath(path) setIsSidebarOpen(false) // 导航后关闭侧边栏 // 在实际应用中,这里会更新浏览器历史记录 - if (typeof window !== 'undefined') { - window.history.pushState({}, '', path) - } + + window.history.pushState({}, '', path) }, [setCurrentPath, setIsSidebarOpen], )