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
Editor styles: cache transform #57810
Conversation
Size Change: +45 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
3873f27
to
28f2fc0
Compare
Flaky tests detected in 28f2fc0. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7514490632
|
@@ -5,6 +5,52 @@ import postcss, { CssSyntaxError } from 'postcss'; | |||
import wrap from 'postcss-prefixwrap'; | |||
import rebaseUrl from 'postcss-urlrebase'; | |||
|
|||
const transformStylesCache = new WeakMap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WeakMap is such a magic tool :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, very!
@@ -18,45 +64,14 @@ import rebaseUrl from 'postcss-urlrebase'; | |||
* @return {Array} converted rules. | |||
*/ | |||
const transformStyles = ( styles, wrapperSelector = '' ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in person, if we're using an iframe, transforming styles might not be necessary anymore assuming we also pass the "url" to the stylesheet in addition to its content. We could just use the URL to load the stylesheets within the iframe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I'll try this next. This PR is still useful for an editor without iframe though (when there's a registered block that is not v3)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
What?
Editor styles settings remain constant for all previews, so we should cache the transforms so the work is not repeated for each preview.
Why?
1st run: -5% (load patterns)
2nd run -5.6%
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast