Skip to content

Commit b1e52d6

Browse files
authored
Mark app ready after initial render (#77)
1 parent f6d661f commit b1e52d6

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
}

frontend/src/app/layout.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Metadata } from 'next'
22
import { Inter } from 'next/font/google'
33
import './globals.css'
44
import { Providers } from './providers'
5+
import { AppReadyEffect } from './components/app-ready'
56

67
const 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>

0 commit comments

Comments
 (0)