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(v2): dont collapse whitespace in minified html #2122

Merged
merged 1 commit into from
Dec 13, 2019
Merged

Conversation

endiliey
Copy link
Contributor

@endiliey endiliey commented Dec 13, 2019

Motivation

Continuation #2116
Tweak minify html to be safer.

  1. Dont collapse whitespace
    Why ?
 var input = '<div> <p>    foo </p>    </div>';
  var output = minify(input, { collapseWhitespace: true });

  output; // '<div><p>foo</p></div>'

This causes our SSR to be weird. Notice "optimizedwebsites" instead of "optimized websites" when javascript is disabled.
minifed html too aggressive

See http://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace

Have you read the Contributing Guidelines on pull requests?

yes

Test Plan

Rendered HTML should be fine now

  • Netlify with JS disabled

@endiliey endiliey added the pr: bug fix This PR fixes a bug in a past release. label Dec 13, 2019
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Dec 13, 2019
@endiliey endiliey added pr: bug fix This PR fixes a bug in a past release. and removed pr: bug fix This PR fixes a bug in a past release. labels Dec 13, 2019
Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

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

Oh yeah good catch. HTML rendering only ignores whitespace sometimes. For example:

<img/><img/>

renders differently from

<img/>
<img/>

because of the new line. In the latter, you will see a small space between the two images lol.

@yangshun yangshun merged commit c036740 into master Dec 13, 2019
@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-preview ready!

Built with commit 584edf3

https://deploy-preview-2122--docusaurus-preview.netlify.com

@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit 584edf3

https://deploy-preview-2122--docusaurus-2.netlify.com

@endiliey endiliey deleted the endi/html-minify branch December 13, 2019 10:15
@lex111
Copy link
Contributor

lex111 commented Dec 16, 2019

I just thought, is this so critical? I mean, who will view the website with JS disabled?

@endiliey
Copy link
Contributor Author

Its not good to have hydration mismatch because React try to patch it up and that can be slow.

Also for slow internet its quite notice-able

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants