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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure @charset is at the top of generated css #4019

Merged
merged 1 commit into from Feb 25, 2021
Merged

Ensure @charset is at the top of generated css #4019

merged 1 commit into from Feb 25, 2021

Conversation

BPScott
Copy link
Member

@BPScott BPScott commented Feb 25, 2021

WHY are these changes introduced?

Fixes #4014

Our generated css file was not handling the consolidation and hoisting of @charset declarations.

WHAT is this pull request doing?

Pulls the @charset declaration up to the top of the file. Will error if there is are multiple competing charsets though that shouldn't ever happen because prettier should force all our source files to be utf-8.

How to 馃帺

  • yarn run build and check dist/styles.css and note that @charset "UTF-8"; is at the top of the file and not half way down.

If you'd like to be more thorough compare output against main:

  • Create a build of main: git checkout main && yarn clean && yarn build && mv dist dist-orig
  • Create a build from this branch: git checkout fix-charset && yarn clean && yarn build
  • Diff the old and new dist folders and note that the only change is the location of the charset in dist/styles.css: diff -ru dist-orig dist

@github-actions
Copy link
Contributor

github-actions bot commented Feb 25, 2021

馃煝 No significant changes to src/**/*.tsx were detected.

@charset must go at the top of the file, not part way down
Copy link
Member

@alex-page alex-page left a comment

Choose a reason for hiding this comment

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

Thanks @BPScott

Copy link
Member

@GoodForOneFare GoodForOneFare left a comment

Choose a reason for hiding this comment

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

馃憤 Output is as described. I want to endlessly bikeshed, but this approach is more concise than anything I'd come up with.

@BPScott
Copy link
Member Author

BPScott commented Feb 25, 2021

I want to endlessly bikeshed

Yeah this is a little hacky. There's probably a smart way to run the single file through postcss again to do this with a proper AST but it's going to be slower than this and I don't think we'll ever run into a case where this this will cause errors - If we end up with multiple file encodings our fix should be "write your source files in UTF8" rather than handle multiple encodings in the build.

@BPScott BPScott merged commit fdfc997 into main Feb 25, 2021
@BPScott BPScott deleted the fix-charset branch February 25, 2021 02:18
sylvhama pushed a commit that referenced this pull request Mar 26, 2021
@charset must go at the top of the file, not part way down
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.

Invalid @charset in dist/styles.css
3 participants