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

Pseudo-element selectors break compiled output #261

Closed
unregistered opened this issue Jul 8, 2017 · 10 comments
Closed

Pseudo-element selectors break compiled output #261

unregistered opened this issue Jul 8, 2017 · 10 comments

Comments

@unregistered
Copy link

On the latest version 1.0.8:

When rendered in a react element:

<style jsx global>{`
	.other-selector {
	  display: none;
	}

	.corrupting-selector:before
	{
	}
`}</style>

I would expect to see:

.other-selector {display: none}

I actually see

<style id="__jsx-style-11968641476">{.corrupting-selector:before;{;}.other-selector{display:none}</style>

Which is invalid CSS, causing other styles defined in that block to be ignored.

I can replicate this by adding that code to one of the test fixtures and running the unit tests as well.

@giuseppeg
Copy link
Collaborator

It might be an issue with empty rules and pseudo selectors, can you remove the empty rule in the meantime? cc @thysultan

@thysultan
Copy link
Contributor

I thought it might be ASI, but i can't reproduce this with stylis, it emits the expected output:

.other-selector#id{display: none;}

@unregistered
Copy link
Author

unregistered commented Jul 8, 2017

@giuseppeg It can still happen when the rules aren't empty. It doesn't even have to be a pseudo-element selector, it might be a parsing issue:

module.exports = `
  .other-selector {
    display: none;
  }

  .bad-selector:hover,
  .bad-selector:focus
  {
      outline: none;
  }
`
"var __styledJsxDefaultExport = new String("{.bad-selector:hover, .bad-selector:focus}.other-selector{display:none}{outline:none}");

Edit: adding content to my original example did fix it though

@unregistered
Copy link
Author

unregistered commented Jul 9, 2017

It also seems to have trouble with the @font-face selector. I recently encountered this gem:

@font-face {
    font-family: 'Custom';
    src: url('/font/Custom.bb4929e353324148ae5f0ee1c395fbd0.eot');
    src: url('/font/Custom.bb4929e353324148ae5f0ee1c395fbd0.eot?#iefix') format('embedded-opentype'), ;
    url('/font/Custom.bb4929e353324148ae5f0ee1c395fbd0.woff2') format('woff2'), url('/font/Custom-Regular.bb4929e353324148ae5f0ee1c395fbd0.woff') format('woff'), url('/font/Custom-Regular.bb4929e353324148ae5f0ee1c395fbd0.ttf') format('truetype');
    font-weight: normal;
    font-style: normal
}

@giuseppeg
Copy link
Collaborator

@unregistered can you paste the original css for the latests snippet?

@giuseppeg
Copy link
Collaborator

{.bad-selector:hover, .bad-selector:focus}

@thysultan this is a bug in stylis and it happens when the curly bracket is in a new line

  .bad-selector:hover,
  .bad-selector:focus
  {

@thysultan
Copy link
Contributor

@giuseppeg This test covers that, what version are you trying this on?

@unregistered
Copy link
Author

unregistered commented Jul 20, 2017

@giuseppeg Here's an example which produces bad output for that latest snippet, if you put it in the unit test suite:

  @font-face {
    font-family: 'Redacted Sans';
    src: url('/font/Redacted-Regular-WebS.eot'); /* IE9 Compat Modes */
    src: url('/font/Redacted-Regular-WebS.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
    url('/font/Redacted-Regular-WebS.woff2') format('woff2'), /* Super Modern Browsers */
    url('/font/Redacted-Regular-WebS.woff') format('woff'), /* Pretty Modern Browsers */
    url('/font/Redacted-Regular-WebS.ttf') format('truetype'); /* Safari, Android, iOS */

    /* Remove this font because it is >200kb
    /* url('/font/Redacted-Regular-WebS.svg#Redacted-Regular-WebS') format('svg'); /* Legacy iOS */

    font-weight: normal;
    font-style: normal;
  }

Result:

.other-selector[data-jsx-ext~=\\"2118869031\\"]{display:none}@font-face{font-family:'Redacted Sans';src:url('/font/Redacted-Regular-WebS.eot');src:url('/font/Redacted-Regular-WebS.eot?#iefix') format('embedded-opentype'),;url('/font/Redacted-Regular-WebS.woff2') format('woff2'), url('/font/Redacted-Regular-WebS.woff') format('woff'), url('/font/Redacted-Regular-WebS.ttf') format('truetype');font-weight:normal;font-style:normal}

The messed up part:
),;url('/font/Redacted-Regular-WebS.woff2')

@thysultan
Copy link
Contributor

Can't seem to reproduce any of them on stylis 3.2.6, so i think an upgrade to 3.2.6 would probably fix these.

giuseppeg added a commit that referenced this issue Jul 20, 2017
@giuseppeg
Copy link
Collaborator

@unregistered fixed in 1.0.9

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

No branches or pull requests

3 participants