Closed Bug 1294863 Opened 8 years ago Closed 6 months ago

Properties & Values API: Change in custom properties registrations should trigger @supports conditions recheck

Categories

(Core :: Layout, defect)

defect

Tracking

()

RESOLVED INVALID

People

(Reporter: jyc, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(3 files)

This is part of implementing the Properties & Values API that has been split off into a separate bug to make Bug 1273706 more manageable.

With the implementation in 1273706, CSS.registerProperty/unregisterProperty will not trigger re-checking of @supports conditions. (@supports conditions previously never needed to be rechecked -- whether or not the rule group would would be used could be determined at parse-time).
Assignee: nobody → jyc
I'm worried this will cause us to do a lot of work if -- in a case I think won't be too uncommon -- we register a few properties at once.  Each call to document.registerProperty() would cause us to re-build the cascade immediately.

I think your GetRuleCascade changes can result in us getting the wrong style, since we don't invalidate the cached rule cascades when the registrations change, we just choose not to use a cached rule cascade at this time.  A following change in media feature will allow us to choose one of the old cached rule cascades.

ClearRuleCascades would be better, as it will remove the cached rule cascades, but that method currently assumes it's being called from CSSStyleSheet::ClearRuleCascades (in response to a style sheet mutation).

I feel like it might be best just to re-use the media queries mechanisms, despite the extra work that nsPresContext::MediaFeatureValuesChanged notifying responsive images and DOM MediaQueryList objects.  (They'll discover that the media features they're interested in haven't changed.)

I think the simplest way to do that would be to add a uint32_t to nsMediaQueryResultCacheKey that stores the custom property registration generation at the time a CSSSupportsRule::UseForPresentation is called.  Since we would only set this field if an @supports rule had a variable registration in it (we can have it be -1 otherwise), we wouldn't need to pay the cost of re-building the cascade if a custom property is registered but we don't have any @supports rules that could be affected by it.

Also, since we would use PostMediaFeaturesChanged we would coalesce multiple registerProperty calls before a style flush.

jyc, dbaron, do you think this sounds workable, and reasonable?  (Though I'm still not quite sure whether @supports should be affected by variable registrations, and the GitHub issue on it is still open.)
Flags: needinfo?(dbaron)
Hi heycam, thanks for looking it over. I am fine with whatever dbaron says. I considered making it a media feature, but that seemed pretty hacky.
Comment on attachment 8780719 [details]
Bug 1294863 - Part 3: Add tests for CSS variable registrations changing causing reevaluation of @supports conditions.

https://reviewboard.mozilla.org/r/71364/#review71902

r=me but like my previous comments, we might need to be more careful when relying on serialiations here.  Also please add some similar tests for CSS.supports() (both the 1-argument and 2-argument versions) with custom properties.

::: testing/web-platform/tests/css-houdini/properties-and-values.html:1000
(Diff revision 2)
> +      // Hopefully don't mess up future tests, although this itself might throw.
> +      CSS.unregisterProperty("--my-property");

Future tests will run in a new document so should have fresh registrations anyway.
Attachment #8780719 - Flags: review?(cam) → review+
Comment on attachment 8780717 [details]
Bug 1294863 - Part 1: Expose nsCSSRuleProcessor's RefreshRuleCascade as a virtual function (default no-op) on nsIStyleRuleProcessor, up through nsStyleSet and nsPresContext.

Cancelling review here for now.
Attachment #8780717 - Flags: review?(cam)
Comment on attachment 8780717 [details]
Bug 1294863 - Part 1: Expose nsCSSRuleProcessor's RefreshRuleCascade as a virtual function (default no-op) on nsIStyleRuleProcessor, up through nsStyleSet and nsPresContext.

https://reviewboard.mozilla.org/r/71360/#review120342
Comment on attachment 8780718 [details]
Bug 1294863 - Part 2: Make CSS variable registrations changing cause reevaluation of @supports conditions.

https://reviewboard.mozilla.org/r/71362/#review71658

::: layout/style/nsCSSRules.h:599
(Diff revision 2)
> +
> +  // Keep track of whether or not mCondition contains any variable references.
> +  // If it does, we will need to re-evaluate mCondition when UseForPresentation
> +  // is called, as variable registrations might change.
> +  bool mHasVariables;

Put this up near mUseGroup to pack the fields together better.
Attachment #8780718 - Flags: review?(cam)

The bug assignee didn't login in Bugzilla in the last 7 months, so the assignee is being reset.

Assignee: jyc → nobody

Redirect a needinfo that is pending on an inactive user to the triage owner.
:dholbert, since the bug has recent activity, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(dbaron) → needinfo?(dholbert)
Flags: needinfo?(dholbert)
Severity: normal → S3

(In reply to Cameron McCormack (:heycam) from comment #7)

jyc, dbaron, do you think this sounds workable, and reasonable? (Though I'm
still not quite sure whether @supports should be affected by variable
registrations, and the GitHub issue on it is still open.)

The spec was changed in 2019 and now contains this section:

As stated in § 2.2 Parse-Time Behavior, both unregistered and registered custom properties accept (almost) all possible values at parse-time. Registered custom properties only apply their syntax at computed value time.
So, all custom properties, regardless of whether they’re registered or unregistered, will test as "true" in an @supports rule, so long as you don’t violate the (very liberal) generic syntax for custom properties.

See https://drafts.css-houdini.org/css-properties-values-api-1/#conditional-rules

Relevant revisions:
https://github.com/w3c/css-houdini-drafts/commit/0eeca05a86688bdf74b6fdc8c4aea712b24cdcb2
https://github.com/w3c/css-houdini-drafts/commit/75ec921d1a842492698f2bb51a9be5ae2023b12c
https://github.com/w3c/css-houdini-drafts/commit/d3c7da48d09d50abfc065808486bd4c3249b9d74

Also, the following test was written to check that change and we currently pass it:
css/css-properties-values-api/conditional-rules.html

Closing this as INVALID.

Status: NEW → RESOLVED
Closed: 6 months ago
Resolution: --- → INVALID

Change dependency since bug 1273706 is now used as a meta bug.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: