Skip to content

Drop duplicate CSS property definitions when curating data #555

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

Merged
merged 4 commits into from
Apr 10, 2022

Conversation

tidoust
Copy link
Member

@tidoust tidoust commented Apr 9, 2022

This adds a new data curation step that drops duplicate CSS property definitions from CSS extracts whenever possible, in other words when we know which definition is the authoritative one. The code contains a list of known superseding relationships between specs to choose the right one. See discussion in #127 for details.

CSS properties that get re-defined in a delta spec are ignored, meaning that a naive merge of all curated CSS extracts will still contain such duplicates. A typical solution to end up with a consistent merge would be to exclude delta specs from that merge. This is left to data consumers as some may choose to rather live on the bleeding edge.

The curated data may still contain duplicate CSS property definitions, but these will get caught by tests. The new tests also check that CSS extracts contain a base CSS property definition for all CSS properties that get extended (through newValues).

This adds a new data curation step that drops duplicate CSS property definitions
from CSS extracts whenever possible, in other words when we know which
definition is the authoritative one. The code contains a list of known
superseding relationships between specs to choose the right one. See discussion
in #127 for details.

CSS properties that get re-defined in a delta spec are ignored, meaning that a
naive merge of all curated CSS extracts will still contain such duplicates. A
typical solution to end up with a consistent merge would be to exclude delta
specs from that merge. This is left to data consumers as some may choose to
rather live on the bleeding edge.

The curated data may still contain duplicate CSS property definitions, but these
will get caught by tests. The new tests also check that CSS extracts contain a
base CSS property definition for all CSS properties that get extended (through
`newValues`).
@tidoust tidoust requested a review from dontcallmedom April 9, 2022 14:51
@tidoust
Copy link
Member Author

tidoust commented Apr 9, 2022

Hmm, there is actually a bug in the code, because require is used to load JSON files throughout, and require caches objects by default. When index.json is loaded by the drop-css-property-duplicates.js module and CSS extracts are expanded, the next step that loads index.json actually sees the result of that expansion, and not the file as it exists on disk. I'll fix that.

Two additional notes:

  • The only properties that remain in the CSS.json extract once this logic is in place are: z-index, page-break-before, page-break-after, and page-break-inside.
  • The logic only covers properties, and does not look at valuespaces and descriptors. It would be good to look into that next.

tidoust added 2 commits April 9, 2022 18:22
The `requireFromWorkingDirectory` function used `require`, which caches objects
in memory. That is good for modules and functions. That is usually a bad idea
for JSON objects that code often modifies in place.

The new loadJSON reads and parses JSON files from storage to avoid conflicts.
This adds unicity of CSS property definitions and presence of base CSS property
definitions to the list of guarantees that we make for CSS extracts.
@tidoust
Copy link
Member Author

tidoust commented Apr 9, 2022

I also completed the READMEs to mention the new guarantees.

The whole thing does not introduce any backward incompatibility, but should we still consider that this should trigger a major bump of the CSS package given that it drops (duplicate) property definitions from a number of CSS extracts?

@tidoust tidoust requested a review from dontcallmedom April 9, 2022 16:55
Copy link
Member

@dontcallmedom dontcallmedom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to major bump

@tidoust tidoust merged commit a0421a8 into main Apr 10, 2022
@tidoust tidoust deleted the drop-duplicate-css-dfns branch April 10, 2022 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants