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

Fix inlined css in every single page. #369

merged 2 commits into from
Jul 17, 2021

Conversation

TomNUSDS
Copy link
Contributor

Fix for issue #366

Created a gatsby-ssr.js to manually remove the css styles embedded in the pages.

SSR means "server side rendering". This fix is from a long github discussion about how broken including all css inline in the file is.

The patch came from here: gatsbyjs/gatsby#1526 (comment)

But honestly, I can't believe there is no flag to control this behavior and the issue was marked "Closed" by the Gatsby folks the way it works now. Especially since newer CSP guidelines say all css should be in a separate file.

The outputted file size for main index.html

Before:   462,099 bytes
After:      3,191 bytes

This is for every single statically generated page.

I tested locally but we should watch for production build issues.

Fix for issue #366

SSR means "server side rendering". This fix is from a long github discussion about how broken including all css inline in the file is. (Especially since newer CSP guidelines say all css should be in a separate file.)
Copy link
Contributor

@NatHillardUSDS NatHillardUSDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, interesting catch, but if it's not running on our prod builds I'm not sure I see the reasoning, though I may be misreading this / misinterpreting the purpose.

In any case it does seem like one of the commenters had to check for a particular property's existence so marking as request changes at least for that; otherwise I'd be curious to tie this back to real-world repercussions also if we can

client/gatsby-ssr.js Outdated Show resolved Hide resolved
client/gatsby-ssr.js Outdated Show resolved Hide resolved
vim-usds
vim-usds previously approved these changes Jul 16, 2021
Copy link
Contributor

@vim-usds vim-usds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a creative fix! Is it safe to say that the styles were duplicated (in-line) and external and this is now just pointing to the external stylesheet?

@TomNUSDS
Copy link
Contributor Author

What a creative fix! Is it safe to say that the styles were duplicated (in-line) and external and this is now just pointing to the external stylesheet?

Yes. The gatsby build processes the files to produce static html output for deploying web pages. This hooks into it to fix an odd behavior in the gatsby sass processing plugin.

@TomNUSDS
Copy link
Contributor Author

Hm, interesting catch, but if it's not running on our prod builds I'm not sure I see the reasoning, though I may be misreading this / misinterpreting the purpose.

In any case it does seem like one of the commenters had to check for a particular property's existence so marking as request changes at least for that; otherwise I'd be curious to tie this back to real-world repercussions also if we can

This gatsby sass plugin hasn't been worked on in a long time and I'm confused why they closed this issue without fixing it. The real fix is to add a flag to the plugin to control this behavior, not have everyone stub their toe on it and then have to add custom code.

@NatHillardUSDS
Copy link
Contributor

Apologies for my misreading, clearly I have Friday Brain. Would be good to go with that extra check I think

* Check el.props['data-href'] is valid
* Add comment for production only.
Copy link
Contributor

@NatHillardUSDS NatHillardUSDS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and good catch!

@TomNUSDS TomNUSDS merged commit dca7980 into main Jul 17, 2021
@TomNUSDS TomNUSDS deleted the tomn-usds/fix-366 branch August 20, 2021 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants