mirror of
https://github.com/Afilmory/afilmory
synced 2026-04-30 17:56:48 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user