File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,9 @@ z.config({ customError: customErrorMap });
3535
3636// Render the app
3737const rootElement = document . getElementById ( "app" ) ;
38- if ( rootElement && ! rootElement . innerHTML ) {
39- const root = ReactDOM . createRoot ( rootElement ) ;
40- root . render (
38+ const isPrerendering = ( window as unknown as { __PRERENDER__ ?: boolean } ) . __PRERENDER__ === true ;
39+ if ( rootElement ) {
40+ const tree = (
4141 < StrictMode >
4242 < ChakraProvider >
4343 < ClerkProvider publishableKey = { CLERK_PUBLISHABLE_KEY } localization = { jaJP } >
@@ -46,8 +46,16 @@ if (rootElement && !rootElement.innerHTML) {
4646 </ ConvexClientProvider >
4747 </ ClerkProvider >
4848 </ ChakraProvider >
49- </ StrictMode > ,
49+ </ StrictMode >
5050 ) ;
51+ if ( ! isPrerendering && rootElement . innerHTML ) {
52+ // Prerender で生成された DOM の上にクライアントで hydrate する。
53+ // hydrate は既存 DOM をそのまま活かしつつイベントハンドラをアタッチするため FOUC もない。
54+ ReactDOM . hydrateRoot ( rootElement , tree ) ;
55+ } else {
56+ // 初回 prerender 実行時、または通常 SPA ルート(#app が空シェル) はそのまま mount。
57+ ReactDOM . createRoot ( rootElement ) . render ( tree ) ;
58+ }
5159}
5260
5361// If you want to start measuring performance in your app, pass a function
You can’t perform that action at this time.
0 commit comments