File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1+ 'use client'
2+
3+ import { useEffect } from 'react'
4+
5+ export function AppReadyEffect ( ) {
6+ useEffect ( ( ) => {
7+ const appElement = document . getElementById ( 'app' )
8+ if ( ! appElement ) {
9+ return
10+ }
11+
12+ let frame1 : number | null = null
13+ let frame2 : number | null = null
14+
15+ const markReady = ( ) => {
16+ appElement . setAttribute ( 'data-ready' , 'true' )
17+ }
18+
19+ frame1 = requestAnimationFrame ( ( ) => {
20+ frame2 = requestAnimationFrame ( markReady )
21+ } )
22+
23+ return ( ) => {
24+ if ( frame1 !== null ) {
25+ cancelAnimationFrame ( frame1 )
26+ }
27+ if ( frame2 !== null ) {
28+ cancelAnimationFrame ( frame2 )
29+ }
30+ }
31+ } , [ ] )
32+
33+ return null
34+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import type { Metadata } from 'next'
22import { Inter } from 'next/font/google'
33import './globals.css'
44import { Providers } from './providers'
5+ import { AppReadyEffect } from './components/app-ready'
56
67const inter = Inter ( { subsets : [ 'latin' ] } )
78
@@ -22,7 +23,10 @@ export default function RootLayout({
2223 < html lang = "en" >
2324 < body className = { inter . className } >
2425 < Providers >
25- { children }
26+ < div id = "app" data-ready = "false" >
27+ < AppReadyEffect />
28+ { children }
29+ </ div >
2630 </ Providers >
2731 </ body >
2832 </ html >
You can’t perform that action at this time.
0 commit comments