Open sanishkr opened 4 years ago
It should be in _app.js
<StyleSheetManager stylisPlugins={language === "ar" ? [stylisRTLPlugin] : []}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
<Page {...pageProps} />
</StyleSheetManager>
Thanks, @Migggz for the suggestion.
I had tried like this in _app.js
:
.
.
.
{language ? (
<StyleSheetManager
stylisPlugins={language === 'ar' ? [stylisRTLPlugin] : []}
>
<Component {...pageProps} />
</StyleSheetManager>
) : null}
.
.
Conditional to do re-rendering when I hit change language. It wasn't working otherwise.
What is CssBaseline
though?
What is CssBaseline though?
Got it. Thanks @oliviertassinari
Can anyone help me why it doesn't work when doing like this:
<StyleSheetManager
stylisPlugins={language === 'ar' ? [stylisRTLPlugin] : []}
>
<Component {...pageProps} />
</StyleSheetManager>
I have to do like this:
{language ? (
<StyleSheetManager
stylisPlugins={language === 'ar' ? [stylisRTLPlugin] : []}
>
<Component {...pageProps} />
</StyleSheetManager>
) : null}
But this approach has its own problems. I have made an example here to look at. Check components/Theme.js
. Just comment line 17 and 23.
@sanishkr Have you found a solution?
Nope. It's a really cool plugin but authors or community doesn't have much support yet.
everything is ok in development mode, when I run the project in production mode, RTL-plugin won't work at first render and if I navigate to another page (in the client) styles will show without any problem
the problem is: server render in production mode:
here is _app.js file:
render() {
const { Component, pageProps, store, lang } = this.props;
const stylePlugins = [];
if (APP_CONSTANTS.LANG[lang].direction === 'rtl') {
stylePlugins.push(rtlPlugin);
}
return (
<Provider store={store}>
<ThemeProvider theme={theme}>
<StyleSheetManager stylisPlugins={stylePlugins}>
<Component {...pageProps} />
</StyleSheetManager>
</ThemeProvider>
</Provider>
);
}
any news on this bug ? StyleSheetManager/stylisRTLPlugin doesn't seem to work at all with nextjs, i followed the guide in styled-components about how to implement in nextjs.
<StyleSheetManager stylisPlugins={[stylisRTLPlugin]}>
the css doesn't flip
Where do I implement in SSR (Next.js)? Should I keep
in StyleSheetManager, it doesn't work.StyleSheetManager
in_app.js
or in_document.js
? I think it should be in _document.js. But I tried wrapping myHere is a sample
_document.js
without this plugin.Here is what I tried