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
When using PrimeVue 4 with Vite SSR, styles are not included in the server-rendered HTML. Since PrimeVue components inject their styles when mounted, this works fine for CSR. However, in SSR, the styles are missing until hydration occurs, causing a flash of unstyled content (FOUC).
Unlike Nuxt (which has a module for handling this), there’s no documented solution for Vite SSR.
Expected Behavior
PrimeVue should provide an official method for injecting styles into the server-rendered output so that the page is fully styled upon initial load.
Current Workaround
To avoid FOUC, I manually extract and inject styles after renderToString, like this:
/// Importsimport{Theme}from'@primeuix/styled'import{Base,BaseStyle}from'@primevue/core'/// Before renderToStringletusedStyles=newSet()Base.setLoadedStyleName=async(name)=>usedStyles.add(name)/// After renderToStringconststyleSheets=[]styleSheets.push(`<style type="text/css" data-primevue-style-id="layer-order">${BaseStyle.getLayerOrderThemeCSS()}</style>`)BaseStyle.getLayerOrderThemeCSS()styleSheets.push(Theme.getCommonStyleSheet())for(constnameofusedStyles){styleSheets.push(Theme.getStyleSheet(name))conststyleModule=awaitimport(`primevue/${name}/style`)styleSheets.push(styleModule.default.getThemeStyleSheet())}styleSheets.push(BaseStyle.getThemeStyleSheet())renderedHead.headTags+=styleSheets.join('\n')
Would love to hear if there’s an official approach to handling this! 🚀
The text was updated successfully, but these errors were encountered:
Issue Description
When using PrimeVue 4 with Vite SSR, styles are not included in the server-rendered HTML. Since PrimeVue components inject their styles when mounted, this works fine for CSR. However, in SSR, the styles are missing until hydration occurs, causing a flash of unstyled content (FOUC).
Unlike Nuxt (which has a module for handling this), there’s no documented solution for Vite SSR.
Expected Behavior
PrimeVue should provide an official method for injecting styles into the server-rendered output so that the page is fully styled upon initial load.
Current Workaround
To avoid FOUC, I manually extract and inject styles after
renderToString
, like this:Would love to hear if there’s an official approach to handling this! 🚀
The text was updated successfully, but these errors were encountered: