Custom Theme is not SSR? App styles flicker on page load. #286
-
Hi there, after following the documentation on creating a custom theme, it seems like the theme is not injected into the document server side. It is served with the default theme, and then when loaded on the client, it converts to the new theme. See in this video how it starts with the default primary blue for a quick second, and then the custom theme kicks in changing it to the desired brand color. Here is my code: pages/_app.js
pages/_document.js
styles/theme.js
In other UI frameworks, such as styled-components, there is a provided method to produce a Am I missing something? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 4 replies
-
Hey @eleazareramos I was looking into this subject and you are right NextUI has a flash theme switch when you set custom values, in the meanwhile, you can use next-themes for fixing it as follows: // _app.js
import { createTheme, NextUIProvider } from "@nextui-org/react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
const customTheme = createTheme({
type: "dark",
theme: {
colors: {
primary: "#AAFFEC",
},
},
});
function App({ Component, pageProps }) {
return (
<NextThemesProvider
defaultTheme="system"
attribute="class"
value={{
dark: customTheme.className,
}}
>
<NextUIProvider>
<Component {...pageProps} />
</NextUIProvider>
</NextThemesProvider>
);
}
export default App; We will try to fix this as soon as possible 👍🏻 |
Beta Was this translation helpful? Give feedback.
-
Great. It worked! Question I'm in a team that's building a startup and decided to use nextui for ui. We could've chosen material ui or bootstrap, but decided to go with nextui because it looks good and it's backed by Vercel I believe, although it's still in beta, we still decided to give it a try. As a startup we dont want to much overhead regarding the technologies we use. So my question is how long will it nextui stay in beta?? When will there be a stable release |
Beta Was this translation helpful? Give feedback.
-
That is awesome, this solution even works for Remix.run! |
Beta Was this translation helpful? Give feedback.
-
Is there a matching issue for this question? I also ran into this problem, and I was helped by a contributor on the Discord who pointed me here, but I'd like to not need the additional |
Beta Was this translation helpful? Give feedback.
-
This hasn't fully fixed the flash for me. (it is a less noticeable, but still there) package.json:
_app.tsx
defaultTheme.tsx
Any help would be GREAT -- maybe I've missed something / implemented next-themes incorrectly |
Beta Was this translation helpful? Give feedback.
Hey @eleazareramos I was looking into this subject and you are right NextUI has a flash theme switch when you set custom values, in the meanwhile, you can use next-themes for fixing it as follows: