Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

Adds Critical CSS extracted by SC to the actual render #505

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitattributes
Empty file.
8 changes: 3 additions & 5 deletions docs/FEATURE_STYLED_COMPONENTS.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# Styled Components

[![Styled Components logo](https://styled-components.com/static/media/logo.333814ad.png "Styled Components")](http://styled-components.com/)
[![Styled Components logo](https://raw.githubusercontent.com/styled-components/brand/master/styled-components.png "Styled Components")](http://styled-components.com/)

This is a feature branch of `react-universally` that is currently built against `v12.0.0`.
This is a feature branch of `react-universally` that is currently built against `v13.0.0`.

It provides you with a simple Style Components integration.

## Known Issues
Currently there is an [issue](https://github.com/styled-components/styled-components/issues/157) trying to use `import` instead of `require` when working with `styled-components`.

Also, there is a [PR pending](https://github.com/styled-components/styled-components/pull/214) for SSR support, so this functionality is not _yet_ available for this branch.

# About

This is the `react-universally-styled-components` feature repository for `react-universally` starter kit.

It provides you with the build tooling and configuration you need to kick off your next universal react project with full support for Styled Components.

Look into `Header` and `Menu` components to check how the wrappers for these are styled using styled-components.
Look into `Header` component to check how its wrapper is styled using `styled-components`.

## What are Styled Components?

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"react-helmet": "5.1.3",
"react-router-dom": "4.1.2",
"serialize-javascript": "1.4.0",
"styled-components": "^2.1.2",
"styled-components": "^2.2.0",
"uuid": "3.1.0"
},
"devDependencies": {
Expand Down
6 changes: 4 additions & 2 deletions server/middleware/reactApplication/ServerHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function scriptTag(jsFilePath) {
// COMPONENT

function ServerHTML(props) {
const { asyncComponentsState, helmet, styleTags, nonce, reactAppString } = props;
const { asyncComponentsState, helmet, styleElement, nonce, reactAppString } = props;

// Creates an inline script definition that is protected by the nonce.
const inlineScript = body =>
Expand Down Expand Up @@ -105,7 +105,7 @@ function ServerHTML(props) {
</KeyedComponent>),
)}
appBodyString={reactAppString}
styleTags={styleTags}
styleElement={styleElement}
/>
);
}
Expand All @@ -117,6 +117,8 @@ ServerHTML.propTypes = {
helmet: PropTypes.object,
nonce: PropTypes.string,
reactAppString: PropTypes.string,
// eslint-disable-next-line react/forbid-prop-types
styleElement: PropTypes.array,
};

// EXPORT
Expand Down
4 changes: 2 additions & 2 deletions server/middleware/reactApplication/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export default function reactApplicationMiddleware(request, response) {
// components are resolved for the render.
asyncBootstrapper(app).then(() => {
const appString = renderToString(sheet.collectStyles(app));
const styleTags = sheet.getStyleTags();
const styleElement = sheet.getStyleElement();
// Generate the html response.
const html = renderToStaticMarkup(
<ServerHTML
reactAppString={appString}
styleTags={styleTags}
styleElement={styleElement}
nonce={nonce}
helmet={Helmet.rewind()}
asyncComponentsState={asyncComponentsContext.getState()}
Expand Down
6 changes: 5 additions & 1 deletion shared/components/HTML/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import PropTypes from 'prop-types';
* The is the HTML shell for our React Application.
*/
function HTML(props) {
const { htmlAttributes, headerElements, bodyElements, appBodyString } = props;
const { htmlAttributes, headerElements, bodyElements, appBodyString, styleElement } = props;

return (
<html {...htmlAttributes}>
<head>
{headerElements}
{styleElement}
</head>
<body>
<div id="app" dangerouslySetInnerHTML={{ __html: appBodyString }} />
Expand All @@ -29,13 +30,16 @@ HTML.propTypes = {
headerElements: PropTypes.node,
bodyElements: PropTypes.node,
appBodyString: PropTypes.string,
// eslint-disable-next-line react/forbid-prop-types
styleElement: PropTypes.array,
};

HTML.defaultProps = {
htmlAttributes: null,
headerElements: null,
bodyElements: null,
appBodyString: '',
styleElement: null,
};

// EXPORT
Expand Down