Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of new Server Rendering API #15277

Closed
raymondsze opened this issue Apr 9, 2019 · 5 comments
Closed

Integration of new Server Rendering API #15277

raymondsze opened this issue Apr 9, 2019 · 5 comments
Labels
docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.

Comments

@raymondsze
Copy link
Contributor

I was using Material UI with Apollo and Next.js.
Previously I use the StylesProvider for the rendering in App Component. I pass disableGeneration as true to StyleProvider to perform Apollo Server-side rendering.

I found that the new guide has been changed to ServerStyleSheet. StylesProvider has been changed to sheets.collect.
I think it is not great to new a ServerStyleSheet and pass sheets.collect to App Component render function. I see the latest example use the ServerStyleSheet in the document.tsx instead of app.tsx.

If I do so, how could I pass disableGeneration during Apollo Server-side rendering? Do I need two ServerStyleSheet instance? If not, how to do that?

And could the nextjs example be enhanced that we could dynamically change the theme color on client-side? I think it is a very common use-case, but its a bit tricky as we have to share the theme color in a memoized context.

@eps1lon eps1lon added the package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5. label Apr 9, 2019
@oliviertassinari oliviertassinari added docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. labels Apr 9, 2019
@oliviertassinari
Copy link
Member

@raymondsze It's a good question. I think that we can update the documentation:

--- a/docs/src/pages/css-in-js/api/api.md
+++ b/docs/src/pages/css-in-js/api/api.md
@@ -120,6 +120,17 @@ import { ServerStyleSheets } from '@material-ui/styles';
 const sheets = new ServerStyleSheets();

+### instance args
+
+The `ServerStyleSheets` instantiation call accepts an `options` object as a first argument.
+The options are spread as props to the [`StylesProvider`](#stylesprovider) component.
+
+```js
+const sheets = new ServerStyleSheets({
+  disableGeneration: true,
+});
+```
+
 ### `sheets.collect(node) => void`

 The method wraps your node in a provider element.

Do you want to give it a shot? 10 issues, 0 pull request, it would be awesome to contribute back :).


For Apollo, you can do:

<StylesProvider disableGeneration>{/* My React Tree */}</StylesProvider>

For the theme color, most people keep it static, now, nothing prevents you from chaning the value. I don't understand.

@heysailor
Copy link

I made repo that uses the new API, including disableGeneration when using Apollo's getDataFromTree: https://github.com/heysailor/material-ui-nextjs

@raymondsze
Copy link
Contributor Author

raymondsze commented Apr 10, 2019

I have a question in mind. If i do sheets.collect(<StylesProvider disableGeneration>...</StylesProvider>).
Would there any "side-effect" introduced as there are two StylesProvider there?

I'm thinking of sticking to old api and directly use StylesProvider instead of ServerStylesSheet. Would like to ask if it would be deprecared or not? or ServerStylesSheet is just a tiny helper for simplification.

@oliviertassinari
Copy link
Member

It's safe to nest two StylesProvider before rendering the UI components.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 10, 2019

The StylesProvider won't be deprecated. The sheet manager and collector are no longer documentation. These two objets are now considered internals. As long as it's documented, you are good.

oliviertassinari pushed a commit that referenced this issue Apr 11, 2019
* update the documentation of ServerStyleSheets api #15277

* small tweaks

* cleanup

* warn about the correct call order

* Seb review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation good first issue Great for first contributions. Enable to learn the contribution process. package: styles Specific to @mui/styles. Legacy package, @material-ui/styled-engine is taking over in v5.
Projects
None yet
Development

No branches or pull requests

4 participants