refactor: remove unnecessary window checks across components

- Eliminated checks for `typeof window !== 'undefined'` in various components and utility functions, simplifying the codebase.
- Updated logic to directly access `window` properties, assuming the code runs in a browser environment.
- Improved readability and maintainability by streamlining conditional checks related to window availability.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2025-11-13 15:03:46 +08:00
parent 76a4c251e4
commit 936666d8a2
16 changed files with 15 additions and 106 deletions

View File

@@ -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