Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inlined css in every single page. #369

Merged
merged 2 commits into from
Jul 17, 2021
Merged
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
25 changes: 25 additions & 0 deletions client/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

/* this is a hack to fix `gatsby-plugin-sass` from including the
css in every single file (which is > 120k lines).
see: https://github.com/gatsbyjs/gatsby/issues/1526
`ssr` means server-side rendering.
*/
export const onPreRenderHTML = ({getHeadComponents}) => {
if (process.env.NODE_ENV !== 'production') { // ONLY run in production
return;
}

getHeadComponents().forEach((el) => {
// Remove inline css. https://github.com/gatsbyjs/gatsby/issues/1526
if (el.type === 'style' && el.props['data-href']) {
el.type = 'link';
el.props['href'] = el.props['data-href'];
el.props['rel'] = 'stylesheet';
el.props['type'] = 'text/css';

delete el.props['data-href'];
delete el.props['dangerouslySetInnerHTML'];
delete el.props['children'];
}
});
};