This is a quick POC to demonstrate server-side-rendering of styled-components.
Currently there are two changes to support this:
-
app/javascript/packs/server_rendering
is modified to return both the rendered component and the style tag containing the styles for that component. -
app/assets/javascripts/application.js
grabs the style tag and moves it to the document<head>
, otherwise it will be discarded by the hydrated component.
After installation of gems and packages.
- Start Rails Server
rails s
-
Visit
http://localhost:3000/examples
and create a new 'Example'. -
Navigate to:
http://localhost:3000/examples/1
with or without JavaScript enabled. The styles are rendered by styled-components.