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

Handle a subset of cyclic issues with statically analyzing the CSS #84

Open
ZeeCoder opened this issue Feb 10, 2018 · 2 comments
Open

Comments

@ZeeCoder
Copy link
Owner

ZeeCoder commented Feb 10, 2018

While container query data is extracted from the css with PostCSS, we could throw an error if the code would obviously cause a loop.

Basically, if a container query on the container itself would apply styles that would invalidate the query based on its conditions, then the query is invalid and should throw an error.

Such a case would be:

div {
  @container (width > 200px) {
    width: 100px;
  }
}

It's easy to see (and detect) why this query would cause a loop, and hence the plugin shouldn't allow for it.

The following however should be fine:

div {
  @container (width > 100px) and (width < 200px) {
    width: 150px;
  }
}

Using the same method, we can predict that after applying the new width value, the query still applies, and so it wouldn't cause a loop, even though the query affects the property it queries.

The following is a more interesting, and still valid case:

div {
  @container (width > 100px) and (width < 200px) {
    width: 150px;
  }

  @container (width > 140px) and (width < 300px) {
    width: 250px;
  }
}

In this case, once the width gets more than 100, it's width first gets snapped to 150px, which in turn immediately triggers the second query, setting the width to 250px, thus ending the evaluation.

The end state is that the width is 250px, with only the second query applying.

Again, no loop occurred, and it seems to be enough to check each query individually if it would invalidate itself.

@tjbenneche
Copy link

This also seems to happen if you change the value for padding on the container element enough that the calculated width brings it back out of the query, e.g. change padding: 16px to padding: 24px at a @container (width > 600px) and the loop will trigger

@ZeeCoder
Copy link
Owner Author

ZeeCoder commented Feb 9, 2019

Yeah I guess certain edge cases could be detected, like:

div {
  width: 90px;
  padding: 10px;

  @container (width >= 100px) {
    padding: 5px;
  }
}

If the width is not specified though, then it's harder to know if it's an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants