Files
zeekay c183da5389 Drop webpack from the stack
The loader and the Next plugin only existed to drive webpack; Next runs
on Turbopack and Vite has its own plugin. kitchen-sink and the
integration app serve through vite, the optimizer suite drops the
webpack name, and its fixture packages join the workspace so a fresh
checkout links @my/ui.
2026-09-06 08:17:57 -07:00

64 lines
1.7 KiB
TypeScript

'use client'
import '@hanzogui/core/reset.css'
import '@hanzo/font/css'
import '@hanzogui/polyfill-dev'
import type { ReactNode } from 'react'
import { useServerInsertedHTML } from 'next/navigation'
import { NextThemeProvider, useRootTheme } from '@hanzogui/next-theme'
import { config } from '@my/ui'
import { Provider } from 'app/provider'
import { StyleSheet } from 'react-native'
export const NextGuiProvider = ({ children }: { children: ReactNode }) => {
const [theme, setTheme] = useRootTheme()
useServerInsertedHTML(() => {
// @ts-ignore
const rnwStyle = StyleSheet.getSheet()
return (
<>
<style
dangerouslySetInnerHTML={{ __html: rnwStyle.textContent }}
id={rnwStyle.id}
/>
<style
dangerouslySetInnerHTML={{
// the first time this runs you'll get the full CSS including all themes
// after that, it will only return CSS generated since the last call
__html: config.getNewCSS(),
}}
/>
<style
dangerouslySetInnerHTML={{
__html: config.getCSS({
exclude: process.env.NODE_ENV === 'production' ? 'design-system' : null,
}),
}}
/>
<script
dangerouslySetInnerHTML={{
// avoid flash of animated things on enter:
__html: `document.documentElement.classList.add('t_unmounted')`,
}}
/>
</>
)
})
return (
<NextThemeProvider
skipNextHead
defaultTheme="light"
onChangeTheme={(next) => {
setTheme(next as any)
}}
>
<Provider defaultTheme={theme || 'light'}>{children}</Provider>
</NextThemeProvider>
)
}