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

CSS optimization breaks when :host-context is included #18672

Open
mcalmus opened this issue Sep 1, 2020 · 2 comments
Open

CSS optimization breaks when :host-context is included #18672

mcalmus opened this issue Sep 1, 2020 · 2 comments

Comments

@mcalmus
Copy link

@mcalmus mcalmus commented Sep 1, 2020

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

Description

A clear and concise description of the problem...

I have a CSS file that is shared between two components, one that uses default encapsulation and one that uses NONE. I have two lines in the CSS as follows:

.darkMode .myLogo {
  color: white;
}
:host-context(.darkMode) .myLogo {
  color: white;
}

This works fine with dev/unoptimized builds. However, when done with a prod/optimized build the resulting CSS combines the two selectors:

.darkMode .myLogo,:host-context(.darkMode) .myLogo{color:white}

The selector is essentially ignored by the browser.

For the component using default encapsulation it similarly works fine regardless of whether optimized or not.

🔬 Minimal Reproduction

🔥 Exception or Error





🌍 Your Environment




Angular CLI: 10.0.8
node: 10.16.3
OS: win32 x64
Angular: 10.0.14

Anything else relevant?

All that I've tried exhibit same issue.

no.

@alan-agius4
Copy link
Collaborator

@alan-agius4 alan-agius4 commented Sep 1, 2020

@nomeaning777
Copy link

@nomeaning777 nomeaning777 commented Sep 9, 2020

I faced the same issue. Workaround is adding an important comment to the :host-context.

.darkMode .myLogo {
    color: white;
}
:host-context(.darkMode) .myLogo {
    /*! Dummy comment to avoid merge host-context and other by cssnano */
    color: white;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.