This commit is contained in:
hailin 2025-06-25 18:46:15 +08:00
parent dcb30caafb
commit 6354af6ea1
2 changed files with 13 additions and 20 deletions

View File

@ -10,7 +10,7 @@ import { cookies } from "next/headers"
import { ReactNode } from "react" import { ReactNode } from "react"
import "./globals.css" import "./globals.css"
import { Suspense } from "react" import { Suspense } from "react"
import { RuntimeEnvProvider } from "@/components/utility/runtime-env-provider" import { RuntimeEnvScript } from "@/components/utility/runtime-env-script"
const inter = Inter({ subsets: ["latin"] }) const inter = Inter({ subsets: ["latin"] })
@ -105,7 +105,7 @@ export default async function RootLayout({
<html lang="en" suppressHydrationWarning> <html lang="en" suppressHydrationWarning>
<head> <head>
<RuntimeEnvProvider /> <RuntimeEnvScript />
</head> </head>
<body className={inter.className}> <body className={inter.className}>

View File

@ -92,12 +92,10 @@
// } // }
// components/utility/runtime-env-provider.tsx // components/utility/runtime-env-script.tsx
import { headers } from "next/headers" import { headers } from "next/headers"
import { useServerInsertedHTML } from "next/navigation"
import React from "react"
export function RuntimeEnvProvider() { export function RuntimeEnvScript() {
const h = headers() const h = headers()
const proto = const proto =
@ -107,18 +105,13 @@ export function RuntimeEnvProvider() {
const supabaseUrl = `${proto}://${hostname}:8000` const supabaseUrl = `${proto}://${hostname}:8000`
useServerInsertedHTML(() => { return (
return ( <script
<script id="runtime-env"
id="runtime-env" dangerouslySetInnerHTML={{
dangerouslySetInnerHTML={{ __html: `window.RUNTIME_ENV = { SUPABASE_URL: ${JSON.stringify(supabaseUrl)} };`,
__html: `window.RUNTIME_ENV = { SUPABASE_URL: ${JSON.stringify( }}
supabaseUrl />
)} };`, )
}}
/>
)
})
return null
} }