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

Normalize @supports queries #720

Open
nmn opened this issue Oct 9, 2024 · 0 comments
Open

Normalize @supports queries #720

nmn opened this issue Oct 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@nmn
Copy link
Contributor

nmn commented Oct 9, 2024

@supports is used in Styles to check support for certain features. However, it is possible to check for the same feature in multiple ways. For example, all of these are valid ways to check for the existence of the dvh unit.

@supports (height: 100dvh) {}

@supports (height: 1dvh) {}

@supports (min-height: 1dvh) {}

@supports (min-height: 50dvh) {}

All of these work in StyleX today. However, if the developer is not careful to use the same check in different parts of the codebase, the generated CSS will have unnecessary duplication.

Is there a way we can solve this?


Automatically?

Is it possible to parse the condition in @supports and ascertain the feature being detected with high confidence in most cases?

Perhaps, if we maintain a list of features that are likely to be tested we can detect the feature being detected in the majority of cases.

If so, we can "normalize" the @supports query into a single canonical form and
optimise the generated CSS.

Explicitly?

If it is not possible to simply detect the intention of the developer by parsing @supports queries, we can instead add explicit API to stylex that can be used to detect certain feature?

So instead of having to write:

const styles = stylex.create({
  root: {
    height: {
      default: '100vh',
      '@supports (height: 100dvh)': '100dvh',
    },
  },
});

A developer may be able to write:

const styles = stylex.create({
  root: {
    height: {
      default: '100vh',
      [stylex.supports.dvh]: '100dvh',
    },
  },
});

The first option is preferable because it doesn't bloat the StyleX API any further and doesn't put the responsibility on the developer to ensure they always use the API from StyleX in order to get the most optimised CSS.

@nmn nmn added the enhancement New feature or request label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant