File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,15 +16,18 @@ function App() {
1616 const location = useLocation ( )
1717 const [ appState , setAppState ] = useState < 'intro' | 'splash' | 'ready' > ( 'intro' )
1818 const [ isFirstVisit , setIsFirstVisit ] = useState < boolean | null > ( null )
19+ const [ isInitialized , setIsInitialized ] = useState ( false )
1920
2021 useEffect ( ( ) => {
2122 const hasVisited = localStorage . getItem ( 'human-os-visited' )
2223 if ( hasVisited ) {
2324 setIsFirstVisit ( false )
24- setAppState ( 'ready ' )
25+ setAppState ( 'splash ' )
2526 } else {
2627 setIsFirstVisit ( true )
28+ setAppState ( 'intro' )
2729 }
30+ setIsInitialized ( true )
2831 } , [ ] )
2932
3033 useEffect ( ( ) => {
@@ -37,20 +40,15 @@ function App() {
3740
3841 const handleIntroComplete = useCallback ( ( ) => {
3942 localStorage . setItem ( 'human-os-visited' , 'true' )
43+ setIsFirstVisit ( false )
4044 setAppState ( 'splash' )
4145 } , [ ] )
4246
4347 const handleSplashComplete = useCallback ( ( ) => {
4448 setAppState ( 'ready' )
4549 } , [ ] )
4650
47- const skipToIntro = useCallback ( ( ) => {
48- if ( isFirstVisit === false ) {
49- setAppState ( 'ready' )
50- }
51- } , [ isFirstVisit ] )
52-
53- if ( isFirstVisit === null ) {
51+ if ( ! isInitialized || isFirstVisit === null ) {
5452 return (
5553 < div className = "fixed inset-0 bg-slate-950 flex items-center justify-center" >
5654 < motion . div
@@ -72,7 +70,7 @@ function App() {
7270 return (
7371 < >
7472 < AnimatePresence mode = "wait" >
75- { appState === 'intro' && isFirstVisit && (
73+ { appState === 'intro' && (
7674 < motion . div
7775 key = "intro"
7876 initial = { { opacity : 1 } }
Original file line number Diff line number Diff line change 1+ import { useState , useEffect , ReactNode } from 'react'
2+ import { motion } from 'framer-motion'
3+
4+ interface FallbackProps {
5+ children : ReactNode
6+ fallback : ReactNode
7+ onError ?: ( ) => void
8+ }
9+
10+ export default function ErrorFallback ( { children, fallback, onError } : FallbackProps ) {
11+ const [ hasError , setHasError ] = useState ( false )
12+
13+ useEffect ( ( ) => {
14+ const handleError = ( event : ErrorEvent ) => {
15+ console . error ( 'Component Error:' , event . error )
16+ setHasError ( true )
17+ onError ?.( )
18+ }
19+
20+ const handleRejection = ( event : PromiseRejectionEvent ) => {
21+ console . error ( 'Unhandled Promise Rejection:' , event . reason )
22+ setHasError ( true )
23+ onError ?.( )
24+ }
25+
26+ window . addEventListener ( 'error' , handleError )
27+ window . addEventListener ( 'unhandledrejection' , handleRejection )
28+
29+ return ( ) => {
30+ window . removeEventListener ( 'error' , handleError )
31+ window . removeEventListener ( 'unhandledrejection' , handleRejection )
32+ }
33+ } , [ onError ] )
34+
35+ if ( hasError ) {
36+ return < > { fallback } </ >
37+ }
38+
39+ return < > { children } </ >
40+ }
Original file line number Diff line number Diff line change 1- import { ReactNode } from 'react'
1+ import { ReactNode , ComponentType } from 'react'
22import Navbar from './Navbar'
33import Footer from './Footer'
44import Background3D from './Background3D'
55import ParticleBackground from './ParticleBackground'
6+ import ErrorFallback from './ErrorFallback'
67
78interface LayoutProps {
89 children : ReactNode
910}
1011
12+ function Background3DWrapper ( ) {
13+ return < Background3D />
14+ }
15+
16+ function ParticleBackgroundWrapper ( ) {
17+ return < ParticleBackground />
18+ }
19+
1120export default function Layout ( { children } : LayoutProps ) {
1221 return (
1322 < div className = "relative min-h-screen bg-gradient-mesh overflow-hidden" >
14- < Background3D />
15- < ParticleBackground />
23+ < ErrorFallback fallback = { < div className = "fixed inset-0 bg-slate-950" /> } >
24+ < Background3DWrapper />
25+ </ ErrorFallback >
26+ < ErrorFallback fallback = { < div className = "fixed inset-0 bg-slate-950/50" /> } >
27+ < ParticleBackgroundWrapper />
28+ </ ErrorFallback >
1629 < div className = "relative z-10" >
1730 < Navbar />
1831 < main className = "min-h-[calc(100vh-64px-80px)]" >
You can’t perform that action at this time.
0 commit comments