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

Fixed an issue in the styles minifier that caused interpolations to be sometimes included more than once in the output #2858

Merged
merged 1 commit into from
Aug 22, 2022

Conversation

Andarist
Copy link
Member

fixes #2745

…e sometimes included more than once in the output
@Andarist Andarist requested a review from srmagura August 21, 2022 22:08
@changeset-bot
Copy link

changeset-bot bot commented Aug 21, 2022

🦋 Changeset detected

Latest commit: 9abf2b9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@emotion/babel-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9abf2b9:

Sandbox Source
Emotion Configuration

@codecov
Copy link

codecov bot commented Aug 21, 2022

Codecov Report

Merging #2858 (9abf2b9) into main (d39379c) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
packages/babel-plugin/src/utils/minify.js 98.75% <100.00%> (-0.06%) ⬇️

Comment on lines -13 to -16
let parent = element
do {
parent = parent.parent
} while (parent && parent.type !== 'rule')
Copy link
Member Author

Choose a reason for hiding this comment

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

No idea why I've included this loop in the past - all tests pass without it. We now directly compare locations of element and element.parent.

The issue was that we temporarily replace interpolations with strings that shouldn't appear in real styles (can be seen here). Such output string is being processed by Stylis (that's why we replace them in the first place, so we can compile styles with Stylis).So Stylis never knows about our little hack and it could, accidentally, treat our string as part of the selector for a rule.

This was happening for input like this:

  ${fullWidth}

  button {

Since it was transformed by us to:

  xxx0:xxx

  button {

And if we had an at-rule within such block then for a rule in it we didn't recognize a rule to be auto-inserted. This information is being utilized by toInputTree which tries to convert the AST back to a shape representing the input string to make it possible to print it back to as a minified string.

Copy link
Member

@srmagura srmagura left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me but I'm going to be honest and say I don't understand the Babel plugin code at all 😂. Sorry I cannot be of more help here.

@Andarist Andarist merged commit 005e211 into main Aug 22, 2022
@Andarist Andarist deleted the fix/2745 branch August 22, 2022 14:20
@github-actions github-actions bot mentioned this pull request Aug 22, 2022
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.

Issue with @emotion/babel plugin - variable reported as not defined
2 participants