You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to figure out the optimal way to load tamagui generated css into my next.js application. The configuration guide suggests either injecting css inline using config.getCSS()or using outputCss to create and import a tamagui.css generated at build time.
However, tamagui's (next.js App Router guide)[https://tamagui.dev/docs/guides/next-js#applayouttsx] does both. This approach seems to contradict the configuration guide's suggestion to only do 1 of the options.
Which is the proper approach?
Also, any idea why disableInjectCSS is not set in the next.js TamaguiProvider? It seems to me like this should definitely be set based on the information from the Configuration doc. Furthermore, it seems to be set in the Pages Router's TamaguiProvider, so I'm wondering if this was intentionally left out in the App Router guide, or just an oversight (I suspect the latter, but figured I'd confirm)
By default, Tamagui injects the CSS for your configuration on the client-side into document.head, but you probably will want something better for production. To do this, pass true to disableInjectCSS on TamaguProvider, and then do one of the following three options:
If your framework has server-side layouts, you can just render it inline:
And then you'll want to import the resulting tamagui.css into your app.
And from the (next.js guide)[https://tamagui.dev/docs/guides/next-js#applayouttsx]:
Create a new component to add TamaguiProvider:
'use client'import'@tamagui/core/reset.css'import'@tamagui/polyfill-dev'import{ReactNode}from'react'import{StyleSheet}from'react-native'import{useServerInsertedHTML}from'next/navigation'import{NextThemeProvider}from'@tamagui/next-theme'import{TamaguiProvider}from'tamagui'importtamaguiConfigfrom'../tamagui.config'exportconstNextTamaguiProvider=({ children }: {children: ReactNode})=>{useServerInsertedHTML(()=>{// @ts-ignoreconstrnwStyle=StyleSheet.getSheet()return(<><styledangerouslySetInnerHTML={{__html: rnwStyle.textContent}}id={rnwStyle.id}/><styledangerouslySetInnerHTML={{// 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: tamaguiConfig.getNewCSS(),}}/></>)})return(<NextThemeProviderskipNextHead><TamaguiProviderconfig={tamaguiConfig}disableRootThemeClass>{children}</TamaguiProvider></NextThemeProvider>)}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to figure out the optimal way to load tamagui generated css into my next.js application. The configuration guide suggests either injecting css inline using
config.getCSS()
or usingoutputCss
to create and import atamagui.css
generated at build time.However, tamagui's (next.js App Router guide)[https://tamagui.dev/docs/guides/next-js#applayouttsx] does both. This approach seems to contradict the configuration guide's suggestion to only do 1 of the options.
disableInjectCSS
is not set in the next.jsTamaguiProvider
? It seems to me like this should definitely be set based on the information from the Configuration doc. Furthermore, it seems to be set in the Pages Router's TamaguiProvider, so I'm wondering if this was intentionally left out in the App Router guide, or just an oversight (I suspect the latter, but figured I'd confirm)Relevant Documentation Snippets
From the tamagui configuration guide:
And from the (next.js guide)[https://tamagui.dev/docs/guides/next-js#applayouttsx]:
Then add it to your app/layout.tsx:
Beta Was this translation helpful? Give feedback.
All reactions