Skip to content

Commit b64d9cf

Browse files
committed
use experimental bootstrap data embedding
1 parent 38f5bac commit b64d9cf

File tree

5 files changed

+15
-34
lines changed

5 files changed

+15
-34
lines changed

flags-sdk/experimentation-statsig/app/layout.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { VercelToolbar } from '@vercel/toolbar/next'
22
import type { Metadata } from 'next'
33
import { Toaster } from 'sonner'
4+
import { FlagBootstrapData } from 'flags/react'
45

56
import './globals.css'
67
import { ExamplesBanner } from '@/components/banners/examples-banner'
@@ -22,13 +23,7 @@ export default function RootLayout({
2223
{children}
2324
<Toaster />
2425
<VercelToolbar />
25-
<script
26-
id="embed"
27-
// biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation>
28-
dangerouslySetInnerHTML={{ __html: '' }}
29-
suppressHydrationWarning
30-
type="application/json"
31-
/>
26+
<FlagBootstrapData />
3227
</body>
3328
</html>
3429
)

flags-sdk/experimentation-statsig/middleware.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { precompute } from 'flags/next'
33
import { productFlags } from '@/flags'
44
import { getStableId } from './lib/get-stable-id'
55
import { getCartId } from './lib/get-cart-id'
6-
import { HTMLRewriter } from 'htmlrewriter'
76
import { statsigAdapter } from '@flags-sdk/statsig'
87
import { identify } from './lib/identify'
98
import { embedBootstrapData } from 'flags/next'

flags-sdk/experimentation-statsig/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
"@vercel/toolbar": "0.1.33",
2424
"motion": "12.17.0",
2525
"clsx": "2.1.1",
26-
"flags": "^4.0.0",
26+
"flags": "4.1.0-c84914eb-20250613112941",
2727
"nanoid": "5.1.2",
28-
"htmlrewriter": "^0.0.12",
2928
"next": "15.4.0-canary.79",
3029
"react": "^19.0.0",
3130
"react-dom": "^19.0.0",

flags-sdk/experimentation-statsig/pnpm-lock.yaml

Lines changed: 9 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flags-sdk/experimentation-statsig/statsig/statsig-provider.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
useClientBootstrapInit,
1616
} from '@statsig/react-bindings'
1717
import { StatsigAutoCapturePlugin } from '@statsig/web-analytics'
18+
import { useBootstrapData } from 'flags/react'
1819
import { createContext, useMemo, useState, useEffect } from 'react'
1920

2021
export const StatsigAppBootstrapContext = createContext<{
@@ -25,16 +26,6 @@ export const StatsigAppBootstrapContext = createContext<{
2526
error: null,
2627
})
2728

28-
export function useEmbed<T>(id: string, initialData?: T) {
29-
const [data, setData] = useState<T | undefined>(initialData || undefined)
30-
useEffect(() => {
31-
// biome-ignore lint/style/noNonNullAssertion: <explanation>
32-
const text = document.getElementById(id)!.textContent
33-
setData(text ? JSON.parse(text) : undefined)
34-
}, [id])
35-
return data
36-
}
37-
3829
function BootstrappedStatsigProvider({
3930
user,
4031
values,
@@ -62,13 +53,12 @@ export function StaticStatsigProvider({
6253
children: React.ReactNode
6354
}) {
6455
// wait for the script#embed to appear and read its contents as json
65-
// TODO use actual embed library
66-
const data = useEmbed<{
56+
const data = useBootstrapData<{
6757
statsigUser: StatsigUser
6858
clientInitializeResponse: Awaited<
6959
ReturnType<typeof Statsig.getClientInitializeResponse>
7060
>
71-
}>('embed')
61+
}>()
7262

7363
const values = useMemo(
7464
() => (data ? JSON.stringify(data.clientInitializeResponse) : null),

0 commit comments

Comments
 (0)