question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

injectGlobal doesn't working in SSR

See original GitHub issue

Version

2.0.0-15

Expected Behavior

I have an injectGlobal style and I want to fetch this CSS on the server.

screen shot 2017-04-27 at 1 43 25 am

Actual Behavior

I’m using const styles = styleSheet.getCSS(); to fetch my current CSS on the server, but it just return the CSS of my components, global styles are not returned.

screen shot 2017-04-27 at 1 38 23 am

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
oscar-bcommented, Apr 27, 2017

Where is your call to injectGlobal?

1reaction
erikrascommented, Apr 27, 2017

For what it’s worth, using the ye olde

const styles = (
  <style
    dangerouslySetInnerHTML={{
      __html: styleSheet.rules().map(rule => rule.cssText).join('\n')
    }}
  />
)

method works with injectGlobal in 2.0.0-15.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to inject global styles while rendering server-side with ...
Turns out, calling baseStyles() (which in turn is calling injectGlobal ) in my <App /> component render() method fixed the problem. :).
Read more >
Releases - styled-components
This is a replacement for the injectGlobal API. ... While this is not guaranteed to work with SSR yet, it can help you...
Read more >
styled-components getting started - Scott Spence
Style the body with injectGlobal. For styling the body of our react app we currently have the index.css file that is being imported...
Read more >
Server Side Rendering - Emotion
The default approach works with streaming and requires no additional configuration, but does not work with nth child or similar selectors.
Read more >
Next.js + Styled Components The Really Simple Guide +
Tagged with react, nextjs, ssr, javascript. ... Amazing the configuration of ".babelrc" was not working with the default configuration of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found