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.

Need update in example code about external stylesheet

See original GitHub issue

In example code about external stylesheet https://github.com/zeit/next.js/tree/master/examples/with-global-stylesheet , it still has dangerouslySetInnerHTML. According to this styled-jsx improvement` https://github.com/zeit/styled-jsx/pull/148, we can reference imported stylesheet now.

I tried to change code and it works.

 export default () =>
   <div>
-    <style dangerouslySetInnerHTML={{ __html: stylesheet }} />
+    <style jsx global>{stylesheet}</style>
     <p>ciao</p>
   </div>

The dangerouslySetInnerHTML does not look right and might trigger eslint error. If my understanding is right, I’ll submit a PR for this.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:18 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
giuseppegcommented, Jul 10, 2017

Alright @mocheng it works indeed! Apparently a combo of babel-plugin-wrap-in-js and webpack’s raw-loader does the trick. But I wouldn’t use it in production yet because the babel plugin doesn’t have tests and when doing server side rendering styled-jsx writes the css in a style tag in the page which means that it is never cached therefore if you have a lot of css and big external files your page size can grow considerably.

Since there is a solution though we might explore ways to allow this in a performant way – maybe we should write external compiled files for SSR in actual .css files and then load them using a regular link tags rather than an inline style.

2reactions
giuseppegcommented, Jul 17, 2017

for regular global styles files I would just serve them from /static and include them in the page with a link tag. You can use a prebuild script to copy or build them into static.

Read more comments on GitHub >

github_iconTop Results From Across the Web

External Style Sheets - Quackit Tutorials
An external style sheet is a separate file where you can declare all the styles that you want to use on your website....
Read more >
HTML and CSS – Inline Style, External Stylesheet, CSS Code ...
There are 3 different ways you can style your HTML: inline styles,; internal styles (also known as embedded CSS), and; external stylesheets. In ......
Read more >
CSS Tutorial For Beginners 06 - External Style Sheets
Hiya ninjas and ninjarettes! In this CSS for Beginners lesson we're going to be looking at why external style sheets are awesome, ...
Read more >
External Style Sheets in CSS: Definition & Examples - Study.com
External style sheets are separate files with a .css extension that are referenced in the main HTML document. Learn cascading order rules to ......
Read more >
How to add CSS - W3Schools
Each HTML page must include a reference to the external style sheet file inside the <link> element, inside the head section. Example. External...
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