Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

react-spaceman and serverside rendering #4

Open
julius-retzer opened this issue Dec 5, 2017 · 7 comments
Open

react-spaceman and serverside rendering #4

julius-retzer opened this issue Dec 5, 2017 · 7 comments

Comments

@julius-retzer
Copy link

julius-retzer commented Dec 5, 2017

Hi again!

Since attachStyles relies on document being defined, I just realized it's currently impossible for us to use it with our CSS modules + SSR setup.

That's a major bummer because we really like it :)

We are considering making a PR but since our setup is a bit specific, maybe we would need to fork, which I would really like to avoid.

Do you have any suggestions how to approach this?

Thanks a lot a for answering these questions!

@sapegin
Copy link
Owner

sapegin commented Dec 5, 2017

It would be very cool to support SSR. If you have any ideas how to do it feel free to send a PR! I guess just checking for document isn’t enough ;-|

@ZauberNerd
Copy link

How about removing jss and just using inline styles? Or writing <style> tags yourself in the <Panel /> component?
You would have a bit of duplication in the generated HTML, but I don't think that will matter much, since it is only one or two attributes per element.

@sapegin
Copy link
Owner

sapegin commented Feb 12, 2018

@ZauberNerd
Copy link

Ah, right I only saw it in the package.json and assumed that it is being used here.

But my proposal is still valid: Don't try to deduplicate css by collecting it and using class names, but instead write either inline styles via the style attribute or inline <style> blocks.

Also: Collecting styles/classes in a module-scoped variable could potentially leak during SSR when the consumer is doing async rendering and multiple request are being handled in the same time, right?

@sapegin
Copy link
Owner

sapegin commented Feb 12, 2018

Don't try to deduplicate css by collecting it and using class names, but instead write either inline styles via the style attribute or inline <style> blocks.

This is something I’m not going to do.

Also: Collecting styles/classes in a module-scoped variable could potentially leak during SSR when the consumer is doing async rendering and multiple request are being handled in the same time, right?

I don’t understand what problems you see here.

@sapegin
Copy link
Owner

sapegin commented Feb 12, 2018

I guess we should extract this code and make CSS available as a string. @Wormyy would that be enough?

// margin-bottom
const belowClasses = addClassesForAllSizes(
'b',
(name, value) => `${name} { margin-bottom: ${value}px }`
);
// padding-left, padding-right
const xClasses = addClassesForAllSizes(
'x',
(name, value) => `${name} { padding-left: ${value}px; padding-right: ${value}px }`
);
// padding-top, padding-bottom
const yClasses = addClassesForAllSizes(
'y',
(name, value) => `${name} { padding-top: ${value}px; padding-bottom: ${value}px }`
);
// Inline
const inlineContainerClass = addClass('i', name => `${name} { display: flex; flex-wrap: wrap }`);
const inlineClasses = addClassesForAllSizes(
'i',
(name, value) => `${name} > *:not(:last-child) { margin-right: ${value}px }`
);
// Stack
const stackClasses = addClassesForAllSizes(
's',
(name, value) => `${name} > *:not(:last-child) { margin-bottom: ${value}px }`
);
attachAllStyles();

@ZauberNerd
Copy link

ZauberNerd commented Feb 12, 2018

Also: Collecting styles/classes in a module-scoped variable could potentially leak during SSR when the consumer is doing async rendering and multiple request are being handled in the same time, right?

I don’t understand what problems you see here.

Assuming you do streaming SSR or use react@16s new async rendering and two requests arrive at almost the same time, the first request starts rendering and therefore fills the module-scoped variable with class names that it has collected during rendering.
Then the second request starts rendering and will reuse the same module-scoped variable as the first request, which means one of these two requests will reset the variable before the other one can render it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants