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

Dependency Cycles via Relative Units with unit algebra #1080

Open
Loirooriol opened this issue Dec 2, 2022 · 3 comments
Open

Dependency Cycles via Relative Units with unit algebra #1080

Loirooriol opened this issue Dec 2, 2022 · 3 comments

Comments

@Loirooriol
Copy link

#315 was fixed without considering "unit algebra". CSS Values 4 allows dividing by dimensions, so we may have

@property --my-font-size {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}
div {
  --my-font-size: calc(10em / 1px);
  font-size: calc(var(--my-font-size) * 1px);
}

That's a dependency cycle! It's not addressed by https://drafts.css-houdini.org/css-properties-values-api/#dependency-cycles, since that only handles registered properties with a syntax of <length> or <length-percentage>.

The example above uses <number>, but other dimensions like <angle> are also affected:

--my-font-size: calc(10em / 1px * 1deg);
font-size: calc(var(--my-font-size) / 1deg * 1px);

CC @tabatkins

@tabatkins
Copy link
Member

Hm, indeed. I think the solution is just to remove the "length or length-percentage" condition (replace it with a "not *" condition, probably), so we add those edges any time the relevant values are used.

@Loirooriol
Copy link
Author

Actually we need more than that, because https://drafts.css-houdini.org/css-properties-values-api/#dependency-cycles isn't really addressing the problem with lengths:

@property --foo {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
div {
  --foo: 10ex;
  font-weight: calc(var(--foo) / 1px);
}

The ex unit depends on font-weight , but the directed dependency graph is not aware of it, since there is only an edge to font-size, not font-weight.

@Loirooriol
Copy link
Author

Following w3c/csswg-drafts#8169 (comment), I guess we should add an edge to every "font-* property (and anything else that affects font selection)".

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