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

Take advantage of CSS Typed OM for performance and bundle size gains #64148

Open
DaniGuardiola opened this issue Jul 31, 2024 · 1 comment
Open
Labels
[Type] Enhancement A suggestion for improvement.

Comments

@DaniGuardiola
Copy link
Member

DaniGuardiola commented Jul 31, 2024

What problem does this address?

In Gutenberg, there are multiple instances of third-party CSS parsing and manipulation tools being included in the user bundle:

The examples above add up to 31.4 kB gzipped (see bundlejs.com) in the bundle, plus these libraries are orders of magnitude slower than native browser APIs.

Additionally, there might be custom logic to manipulate CSS, like the one being proposed here as part of #63915

What is your proposed solution?

While pairing with @mirka on reviewing her PR (#63915), we thought about the CSS Typed OM API which is described in MDN like this:

"The CSS Typed Object Model API simplifies CSS property manipulation by exposing CSS values as typed JavaScript objects rather than strings."

The instances mentioned above could be refactored to use the CSS Typed OM API so that we can shave off a significant amount of third-party code from the bundle and get significant performance gains.

While there's no Firefox support yet (it's a work in progress), there's a relatively small (3.22 kB gzipped) polyfill that could be removed later on.

@DaniGuardiola DaniGuardiola added the [Type] Enhancement A suggestion for improvement. label Jul 31, 2024
@mirka
Copy link
Member

mirka commented Jul 31, 2024

I was looking into the css-typed-om polyfill, and unfortunately it states that it's a work in progress, not to be used in production. There's no movement on it since six years ago so we can assume it is dead, but based on the feature implementation status analysis of a developer that forked it, CSSStyleValue.parse() (which will be crucial to our needs) is at "bare minimum functionality". Even for relatively narrow-scope applications, we'd have to put in the rigorous testing effort ourselves to ensure that it supports what we need.

I wonder if it would be better to wait until it ships in Firefox 🙁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants