Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Duotone: Pass filters to the Post Editor #49239
Changes from 5 commits
a98c60b
32355ba
7810e0a
0e6304e
690cca4
5a99e30
8f9541e
2b8484b
6a19107
6e0d5c0
44e46c8
0b4dfe7
9f84812
57471f9
05121a2
20a6fde
9b4e96c
4fb10d4
5fe3835
32f2147
3688db6
f426d62
0dabaf4
6bc19a9
a0be2bf
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 is a potentially subtle issue, but the filter here appears to be to ensure that the
svg
elements provided by the backend data aren't included intransformedStyles
.When this change is eventually backported, it'll likely happen at slightly different times, typically with the PHP changes landing before the JS changes.
Would it be possible or worthwhile to have the
svg
elements in a different part of the block editor settings, so that if the backend changes land first, the frontend doesn't get tripped up if this code hasn't landed in the JS side yet?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.
Hmmm... I can see how that's an issue, but I don't have any good ideas for how to solve it right now. Since we've decided to keep
svgs
part ofstyles
, we're going to have to have JS changes added before PHP changes no matter what. We might just have to leave a note about it.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.
That sounds reasonable to me, if it's the right path forward for the feature. It'd be good to make sure the comments are clear in the PHP code for when it comes time to backport, so that we don't forget 🙂
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'm not sure if this is what you're talking about, but I added a comment in the php in a0be2bf.
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
, sotransformedSvgs
would just contain the definitions.And the final output would look like this.
Instead of what we currently have in this PR.
In the frontend, doing something similar could maybe shave off another kilobyte if there are a lot of filters on the page.
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 are we adding non styles to
EditorStyles
and then moving everything in the body? Why not add SVGs separately here?Also what if we move this to the iframe component in the block-editor package? Wouldn't it then work automatically in all editors and allow us to remove a bunch of duplication?
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.
That was my suggestion and for me these SVG filters are styles. They're just not "CSS styles". Basically if you check the code base, in all the places we use
EditorStyles
or generate the "styles" key we need to do the same for the "filters". It's an indication that they are the same thing, it's just the technology that changes.The move to body is necessary because the filters can't be inserted into head in HTML. I suggest that we could potentially use ownerDocument to solve that.
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, you could use a portal. Maybe we should build
EditorStyles
into theIframe
component as well?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.
@ellatrix Is it okay if that's handled in a follow-up? Or do you think it's important for this PR?
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 tried doing this, but it causes a flash of unstyled content while React is grabbing the ref to use for the portal. Is there any reason we can't have the
<style>
elements in the<body>
of the document?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.
EditorStyles
aren't used exclusively in theIframe
component. We'd want them to work in those cases too.