Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

theming: parsing a registered style with Media Queries or keyframes produces incorrect rules #9869

Closed
natete opened this issue Oct 20, 2016 · 2 comments · Fixed by #12049
Closed
Assignees
Labels
has: Pull Request A PR has been created to address this issue P2: required Issues that must be fixed. resolution: fixed type: bug ui: CSS
Milestone

Comments

@natete
Copy link
Contributor

natete commented Oct 20, 2016

Actual Behavior:

  • What is the issue? * When a CSS stylesheet containing media queries (or keyframes or anything that can have nesting) is registered using the Theming Provider, Angular Material processes it in a wrong way causing an incorrect result.

Now the string representing the CSS is split using a regex that doesn't take into account nesting, causing nested rules to be considered independent rules. For example:

@media (min-width: 0) and (max-width: 700px) {

  .md-THEME_NAME-theme .test-background {     
    background-color: pink;
  }

  .md-THEME_NAME-theme p {
    color: blue;
    font-weight: bold;
  }
}

Will be parsed:

@media (min-width: 0) and (max-width: 700px) {

  .md-test-theme .test-background {     
    background-color: pink;
  }
}

.md-test-theme p {
  color: blue;
  font-weight: bold;
}

Causing a bad behavior because styles defined to p elements will be applied regardless the screen size.

  • What is the expected behavior? Parsing a CSS should take into account nesting. In the example the correct result would be:
@media (min-width: 0) and (max-width: 700px) {

  .md-test-theme .test-background {     
    background-color: pink;
  }

  .md-test-theme p {
    color: blue;
    font-weight: bold;
  }
}

CodePen (or steps to reproduce the issue): *

  • CodePen Demo which shows your issue: http://codepen.io/natete/pen/BLGPbd
  • Details: Second rule inside the media query is extracted from it causing the rules to be applied in a wrong manner.

Angular Versions: *

  • Angular Version: 1.5.8
  • Angular Material Version: 1.1.1

Additional Information:

  • Browser Type: * all
  • Browser Version: * all
  • OS: * all
  • Stack Traces:

Shortcut to create a new CodePen Demo.
Note: * indicates required information. Without this information, your issue may be auto-closed.

Do not modify the titles or questions. Simply add your responses to the ends of the questions.
Add more lines if needed.

natete added a commit to natete/material that referenced this issue Oct 20, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 20, 2016
Add a new test to validate the style generated by registerStyle when CSS has nested rules.

References angular#9869
@ThomasBurleson ThomasBurleson added the P0: critical Critical issues that must be addressed immediately. label Oct 20, 2016
@ThomasBurleson ThomasBurleson added this to the 1.1.2 milestone Oct 20, 2016
natete added a commit to natete/material that referenced this issue Oct 21, 2016
Apply suggested corrections to improve code style.

References angular#9869
natete added a commit to natete/material that referenced this issue Oct 22, 2016
Ignore anything inside quotes to prevent bad parsing when a curly brace is found inside quotes as in
a content rule

 References angular#9869
natete added a commit to natete/material that referenced this issue Oct 23, 2016
…levels

Add a new to validate the style generated by registerStyle when the CSS has multiple levels of
nesting.

 References angular#9869
natete added a commit to natete/material that referenced this issue Oct 23, 2016
@clshortfuse clshortfuse added the has: Pull Request A PR has been created to address this issue label Oct 24, 2016
natete added a commit to natete/material that referenced this issue Oct 24, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 24, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 24, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 24, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 24, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 24, 2016
 Replace the regex used to split the CSS string with a function that takes into account nested rules.

 Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 25, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 25, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 25, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
natete added a commit to natete/material that referenced this issue Oct 25, 2016
Replace the regex used to split the CSS string with a function that takes into account nested rules.

Fixes angular#9869
@clshortfuse
Copy link
Contributor

@EladBezalel the attached PR was failing tests and wasn't committed. Might need a fresh attempt.

@ThomasBurleson ThomasBurleson modified the milestones: 1.1.2, 1.1.4 Feb 4, 2017
@ThomasBurleson ThomasBurleson modified the milestones: 1.1.4, 1.1.5 May 7, 2017
@Splaktar Splaktar modified the milestones: 1.1.11, 1.1.12 Sep 7, 2018
@Splaktar Splaktar modified the milestones: 1.1.12, 1.1.13 Jan 3, 2019
@Splaktar Splaktar modified the milestones: 1.1.13, 1.1.14 Feb 10, 2019
@Splaktar Splaktar modified the milestones: 1.1.14, 1.1.15 Mar 14, 2019
@Splaktar Splaktar modified the milestones: 1.1.15, 1.1.16, 1.1.18, 1.1.19 Mar 29, 2019
@Splaktar Splaktar modified the milestones: 1.1.19, 1.1.21 May 30, 2019
@Splaktar Splaktar modified the milestones: 1.1.21, 1.1.22 Aug 15, 2019
@Splaktar Splaktar modified the milestones: 1.1.22, 1.1.23 Oct 22, 2019
@Splaktar Splaktar modified the milestones: 1.1.23, 1.2.0 Jun 8, 2020
@Splaktar Splaktar modified the milestones: 1.2.0, 1.2.1 Jul 29, 2020
@Splaktar Splaktar modified the milestones: 1.2.1, 1.2.2 Sep 14, 2020
@Splaktar
Copy link
Member

Splaktar commented Dec 6, 2020

Some details on the given CodePen and this reproduction:

  • You have to reproduce this on a small display (700px wide or smaller)
  • You see white text instead of blue because the CSS rule is rendered as
.md-test-theme * {
    color: blue;
    font-weight: bold;
    font-size: 6px;
}

Instead of

@media (max-width: 700px) and (min-width: 0) .md-test-theme * {
    color: blue;
    font-weight: bold;
    font-size: 6px;
}

Broken

Screen Shot 2020-12-05 at 21 06 08

It should render this way

Screen Shot 2020-12-05 at 21 05 44

Splaktar pushed a commit that referenced this issue Dec 6, 2020
- replace the regex used to split the CSS string with a function that takes into account nested rules
- remove unused `ruleMatchRegex`

Fixes #9869
Splaktar pushed a commit that referenced this issue Dec 9, 2020
- replace the regex used to split the CSS string with a function that takes into account nested rules
- remove unused `ruleMatchRegex`

Fixes #9869
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.