[V2] Using SSR API on client side
See original GitHub issueI still can’t find a way to extract styles from client side with SC2. With SC1, I did it this way:
[render static component...]
let cssRules = StyleSheet.rules().map(rule => rule.cssText).join('\n');
When upgrading to SC2, I switch to the new SSR API:
let sheet = new ServerStyleSheet();
[render static component...]
let cssRules = sheet.getStyleTags();
But since I’m on client side, I get the “BrowserTag cannot be cloned!” error when trying to create the ServerStyleSheet object (see #811).
Digging the source code, I find this way to do it:
[render static component...]
let cssRules = StyleSheet.instance.toHTML();
But it generates several <styles>
tags, some with data-styled-components
attributes, some comments…not a very clean stylesheet.
What is the proper way to extract SC <styles>
from the client side, with or without SSR API ?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:20 (10 by maintainers)
Top Results From Across the Web
Client-side vs. Server-side vs. Pre-rendering for Web Apps
SSR is used to fetch data and pre-populate a page with custom content, leveraging the server's reliable internet connection. That is, the server's...
Read more >Server-side rendering - Apollo GraphQL Docs
Server -side rendering (SSR) is a performance optimization for modern web apps. It enables you to render your app's initial state to raw...
Read more >Server Side Rendering (SSR) vs. Client Side Rendering (CSR ...
Client Side Rendering means generating the HTML components on the browser side, by executing Javascript code within the browser that manipulates the HTML ......
Read more >Server-Side Rendering (SSR) - Vue.js
Code Structure # · Serve client files by adding server.use(express.static('.')) in server.js . · Load the client entry by adding <script type="module" src="/ ......
Read more >How to stop 2 times data fetch in SSR (first on server side and ...
Now issue is that after fetching data on server, client is again calling fetchRequestQuery(dispatch) in useEffect. so it is calling same API 2...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m using React to build a static page editor/generator, so I need at some point to extract the HTML (with React renderStatic…) and the styles (with SC). At this stage I do everything on the client side. In the end, I may split the app with a server, or not: I may embed the app in an Electron like wrapper, so I’ll still need to extract the style from the client side.
Sure, it is pretty simple:
In fact, I have my own snapshot serializer that produces nice snapshots of input element, its rendered output and captured css.