-
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
Fix external styles leaking into Warning component #40868
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Size Change: +2.81 kB (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
michalczaplinski
changed the title
Add gutenberg-warning custom element
Fix external styles leaking into Warning component
May 9, 2022
luisherranz
approved these changes
May 10, 2022
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 Michal!
Awesome, thanks a lot @michalczaplinski! |
1 task
ockham
added
Backport to WP 6.7 Beta/RC
Pull request that needs to be backported to the WordPress major release that's currently in beta
[Block] Comments (legacy)
The legacy mode of the Comments block (formerly known as Post Comments)
labels
May 11, 2022
adamziel
pushed a commit
that referenced
this pull request
May 16, 2022
* Add gutenberg-warning custom element * Add only a wrapping div with all: initial * Update jest snapshot * Update the test case
I just cherry-picked this PR to the wp/6.0 branch to get it included in the next release: 7df643f |
adamziel
removed
the
Backport to WP 6.7 Beta/RC
Pull request that needs to be backported to the WordPress major release that's currently in beta
label
May 16, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[Block] Comments (legacy)
The legacy mode of the Comments block (formerly known as Post Comments)
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.
What?
Fix #40536
Why?
External styles have been leaking into the
<Warning />
component.How?
Using the the
all: initial
anddisplay: content
. Some of the previous approaches are summarized in #40536 (comment)Initially, I've tried to use the Shadow DOM to fix this as suggested in #40847 (comment)
I've have since realised that the Shadow DOM prevents the styles inside of it from leaking to the outside but we needed the opposite - the component NOT to be affected by the outside styles.
The key to figuring out this problem was realizing that certain CSS properties are inheritable and that they are the ones that are "leaking" into the
<Warning/>
component and messing up the styling. The Shadow DOM does not prevent those properties from being inherited. In order to prevent this, we needall: initial
(as also mentioned in the linked article).I've also considered marking only the inheritable properties with
initial
but it's not necessary. This is because the "wrapping" div gets all of its styles reset toinital
but its descendants are only influenced by the inheritable styles:Caveats
There are two (related) caveats with this approach that I'm not 100% happy with but I guess we can live with them:
Styles in our reset.css are NOT going to be applied to the
<Warning/>
.User Agent styles are NOT going to be applied either.
I have noticed that there is a tiny discrepancy in how the warnings render pre- and post- this PR. I think this is because some padding is defined in
em
and settingall: initial
resets thefont-size
which is what controls the "unit" of theem
:2022-05-09_19-37-08.mp4
Screenshots or screencast
(This is outdated because it was made when the PR was not finished):
https://www.loom.com/share/2b82de57b1b44ba9a21ebc84150642b1