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 there is more than one emotion cache I want the global style to always be at the top and then be overridden in order
The prepend option can only be set to the top or bottom, and the insertionPoint option needs to be passed HTMLElement which does not support SSR
I can adjust the order of ServerStyles here, but there's no way to override the mantine style directly
Thanks for the report. I don't see how to solve this... the expected behavior shows the mantine styles being inserted in the middle of the styles for the main Emotion cache.
@Andarist Thanks for the solution, but to make it easier to override styles I'd like to be able to have my own non-global styles after the mantine styles
Client-side rendering
I don't quite understand, this doesn't seem to solve the problem, and insertionPoint only works on client-side rendering. Even if it were possible, the results of server-side and client-side rendering would be inconsistent, right?
If I just put the mantine style at the end I would just adjust the order of the ServerStyles in the _document and set the emotionOptions.prepend of mantine to false and it would have the same effect
@Andarist Thanks for the solution, but to make it easier to override styles I'd like to be able to have my own non-global styles after the mantine styles
Since global styles are not scoped anyway you could use 2 separate caches for this - one cache for global styles with insertionPointbefore Mantine styles and one for scoped styles with insertionPointafter Mantine styles. Since Mantine is also using Emotion under the hood - you'd probably have to introduce an insertionPoint for it too (between those other two).
I don't quite understand, this doesn't seem to solve the problem, and insertionPoint only works on client-side rendering. Even if it were possible, the results of server-side and client-side rendering would be inconsistent, right?
With extractCritical, that you are using, you can just "manually" insert those rendered styles at the correct location (right after insertionPoint). You would have to implement this manually~ without the help of the ServerStyles "helper" that you are using.
Since those extracted styles are rendered into <head/> during SSR anyway - you won't have SSR mismatches as your client-side React won't even see your <head/>.
@Andarist I got it, thanks! I've considered extracting global styles to a separate cache before, so that server-side rendering only requires adjusting the ServerStyles order, and client-side rendering only requires setting the insertionPoint of the Mantine!
It seems that cache.compat = true is the main point, can you elaborate on this?
It seems that cache.compat = true is the main point, can you elaborate on this?
This is automatically set to true by createEmotionServer. It makes our APIs not to render styles "inline" during SSR - they are just put into the cache as it's expected that they will be extracted using APIs like extractCritical etc. It also turns off the infamous "unsafe pseudo-selectors" warnings.
With your latest patch - is it already working as you want? Or do you need further assistance?
This is automatically set to true by createEmotionServer. It makes our APIs not to render styles "inline" during SSR - they are just put into the cache as it's expected that they will be extracted using APIs like extractCritical etc. It also turns off the infamous "unsafe pseudo-selectors" warnings.
With your latest patch - is it already working as you want? Or do you need further assistance?
@Andarist Thank you! This problem has been solved ð
Activity
srmagura commentedon Jul 2, 2022
Thanks for the report. I don't see how to solve this... the expected behavior shows the
mantinestyles being inserted in the middle of the styles for the main Emotion cache.Somewhat similar issue: #2790
Andarist commentedon Jul 4, 2022
You can use this patch to work around your issue:
patch for the repro
u3u commentedon Jul 9, 2022
Disable JavaScript Server-side rendering
@Andarist Thanks for the solution, but to make it easier to override styles I'd like to be able to have my own non-global styles after the
mantinestylesClient-side rendering
I don't quite understand, this doesn't seem to solve the problem, and
insertionPointonly works on client-side rendering. Even if it were possible, the results of server-side and client-side rendering would be inconsistent, right?If I just put the
mantinestyle at the end I would just adjust the order of theServerStylesin the_documentand set theemotionOptions.prependofmantinetofalseand it would have the same effectAndarist commentedon Jul 9, 2022
Since global styles are not scoped anyway you could use 2 separate caches for this - one cache for global styles with
insertionPointbefore Mantine styles and one for scoped styles withinsertionPointafter Mantine styles. Since Mantine is also using Emotion under the hood - you'd probably have to introduce aninsertionPointfor it too (between those other two).With
extractCritical, that you are using, you can just "manually" insert those rendered styles at the correct location (right afterinsertionPoint). You would have to implement this manually~ without the help of theServerStyles"helper" that you are using.Since those extracted styles are rendered into
<head/>during SSR anyway - you won't have SSR mismatches as your client-side React won't even see your<head/>.u3u commentedon Jul 9, 2022
Disable JavaScript Server-side rendering
Client-side rendering
@Andarist I got it, thanks! I've considered extracting global styles to a separate cache before, so that server-side rendering only requires adjusting the
ServerStylesorder, and client-side rendering only requires setting theinsertionPointof the Mantine!It seems that
cache.compat = trueis the main point, can you elaborate on this?My solution: u3u/emotion-issue-2803@2a302de
git patch
Andarist commentedon Jul 10, 2022
This is automatically set to
truebycreateEmotionServer. It makes our APIs not to render styles "inline" during SSR - they are just put into the cache as it's expected that they will be extracted using APIs likeextractCriticaletc. It also turns off the infamous "unsafe pseudo-selectors" warnings.With your latest patch - is it already working as you want? Or do you need further assistance?
u3u commentedon Jul 10, 2022
@Andarist Thank you! This problem has been solved ð