-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Duotone: Pass filters to the Post Editor #49239
Conversation
Size Change: +1.44 kB (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
Flaky tests detected in a0be2bf. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4514581517
|
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 0 0" | ||
width="0" | ||
height="0" | ||
focusable="false" | ||
role="none" | ||
dangerouslySetInnerHTML={ { __html: transformedSvgs } } | ||
/> |
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.
Since we're adding all this front matter in this case and we're outputting them all at once in the frontend too, there's another performance improvement that we can make with duotone filters by wrapping all the filter definitions in a single SVG wrapper like this.
Not for this PR, but as a follow-up.
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.
Why would that be more performant?
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.
Re-reading what I wrote, I really didn't explain that well. What I'm saying is that we can have one wrapper for all the SVG defs
, so transformedSvgs
would just contain the definitions.
<filter id="wp-duotone-grayscale">
<feColorMatrix ... />
<feComponentTransfer ...>...</feComponentTransfer>
<feComposite ... />
</filter>
<filter id="wp-duotone-midnight">
...
</filter>
...
And the final output would look like this.
<svg xmlns="http://www.w3.org/2000/svg" ... />
<defs>
<filter id="wp-duotone-grayscale">
<feColorMatrix ... />
<feComponentTransfer ...>...</feComponentTransfer>
<feComposite ... />
</filter>
<filter id="wp-duotone-midnight">
...
</filter>
...
</defs>
</svg>
Instead of what we currently have in this PR.
<svg xmlns="http://www.w3.org/2000/svg" ... />
<svg xmlns="http://www.w3.org/2000/svg" ... />
<defs>
<filter id="wp-duotone-grayscale">
<feColorMatrix ... />
<feComponentTransfer ...>...</feComponentTransfer>
<feComposite ... />
</filter>
</defs>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" ... />
<defs>
<filter id="wp-duotone-midnight">
...
</filter>
</defs>
</svg>
...
</svg>
In the frontend, doing something similar could maybe shave off another kilobyte if there are a lot of filters on the page.
packages/edit-site/src/components/block-editor/editor-canvas.js
Outdated
Show resolved
Hide resolved
I've made all of the requested changes, but I ended up reverting the change using a portal to render the |
Thanks for all the work, this is looking good to me. Should we also update the output of
|
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.
I still don't understand why we have to use EditorStyles
. Why not make a separate component for SVGs or even just build it straight into the Iframe
component?
@ellatrix Because for me, these are editor styles. What would we want to separate some editor styles rendered in one component, while the others rendered by something else? Rendering in head or body is an implementation detail for me. I understand that it creates friction here but if we really want to keep the styles in head and svgs in body, I think it should still be possible to do within the same component. |
… SVG elements in filterSvgs
packages/block-editor/src/components/global-styles/use-global-styles-output.js
Show resolved
Hide resolved
packages/block-editor/src/components/global-styles/use-global-styles-output.js
Show resolved
Hide resolved
My mistake for missing that—you mentioned it earlier. Fixed in 0dabaf4. |
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.
This LGTM 👍
I really like how this just removes the need for us to think about SVG filters anymore.
What?
Resolves the issue where global block style duotone filters were not applied in the post editor.
Why?
Fixes #48586
How?
<EditorStyles>
into the<body>
of the post editor iframe because SVG elements are not valid children of<head>
.<EditorStyles>
to handlestyles
with__unstableType: 'svgs'
duotone
to populate thestyles
with SVGs and CSS custom properties.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
Before (post editor)
After (post editor)
Co-authored-by: Alex Lende 5129775+ajlende@users.noreply.github.com