@@ -10,7 +10,7 @@ Note: Renders Spline scene as hero section background overlay.
1010
1111"use client" ;
1212
13- import { useState } from 'react' ;
13+ import { useState , useEffect } from 'react' ;
1414import dynamic from 'next/dynamic' ;
1515
1616const Spline = dynamic ( ( ) => import ( '@splinetool/react-spline' ) , {
@@ -22,13 +22,29 @@ export default function HeroBackground() {
2222 const [ isLoaded , setIsLoaded ] = useState ( false ) ;
2323 const [ shouldLoad , setShouldLoad ] = useState ( false ) ;
2424
25- // Defer loading of the heavy 3D scene to prioritize initial page interactivity
26- useState ( ( ) => {
27- const timer = setTimeout ( ( ) => {
28- setShouldLoad ( true ) ;
29- } , 2500 ) ;
30- return ( ) => clearTimeout ( timer ) ;
31- } ) ;
25+ // Defer loading of the heavy 3D scene to completely avoid blocking initial performance metrics
26+ useEffect ( ( ) => {
27+ let timer : NodeJS . Timeout ;
28+
29+ const startLoading = ( ) => {
30+ // Wait 10 seconds after page is fully loaded before loading the 3D scene
31+ timer = setTimeout ( ( ) => {
32+ setShouldLoad ( true ) ;
33+ } , 10000 ) ;
34+ } ;
35+
36+ // Wait for the page to be fully loaded (all resources downloaded)
37+ if ( document . readyState === 'complete' ) {
38+ startLoading ( ) ;
39+ } else {
40+ window . addEventListener ( 'load' , startLoading ) ;
41+ }
42+
43+ return ( ) => {
44+ clearTimeout ( timer ) ;
45+ window . removeEventListener ( 'load' , startLoading ) ;
46+ } ;
47+ } , [ ] ) ;
3248
3349 return (
3450 < div className = "absolute inset-0 z-0 flex items-center justify-center" >
0 commit comments