-
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
Improve cover z-index solution #66249
Improve cover z-index solution #66249
Conversation
cccb26d
to
e9c5f0b
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
I'm already opening it for review, but it still has some test issues. I tried to update the fixtures through |
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.
Thank you for following up on #66093 @renatho 👍
I've taken this for a test drive. It's coming together well but I did run into a few issues.
✅ Cover z-index behaviour works as expected post migration
✅ Deprecated blocks appear to migrate in the editor
✅ Deprecated blocks still render appropriately on the frontend
❌ After saving the post and reloading, the deprecated blocks don't appear to have been migrated i.e. they retrigger the deprecation. Making an unrelated edit and resaving the post seems to apply the updates the second time around.
Screen.Recording.2024-10-21.at.3.06.58.pm.mp4
In addition to the migration issue flagged above, I've left a few other thoughts as inline comments where applicable.
These include:
- We should be able to avoid introducing the new CSS class to the markup by using CSS sibling selectors for both the latest and BC styles.
- This would also mean that less blocks would need to be migrated, perhaps mitigating a tiny bit of the performance hit.
- i.e. only blocks with both the color overlay and an image or video would have their markup changed requiring a migration.
- As the original fix is slated for release in 19.6, we could avoid the need to include styles for
.has-modal-open
for BC reasons.- I understand the consistency argument but simply including it for no functional reason and setting a precedent for a block in the editor to mess with the document root classes feels like a stretch.
- Happy to hear others' thoughts on that one. My vote is remove it, we can always add it when there is a pressing need.
- We need a new fixture to cover this latest deprecation.
- All the non-deprecation-related fixtures for the cover block need to be updated to the latest markup structure.
- This is why the fixture regeneration is throwing the error around an unexpected deprecation being run.
- After the above fixture updates, regenerating the fixtures should succeed and the result should be something like past deprecation's serialized HTML being updated to the correct structure.
I suspect that in the process of ironing out the deprecation, the bug I noticed while testing will be uncovered and resolved 🤞
@renatho let me know if anything around my recommendations for the deprecation tweaks isn't clear.
8835572
to
a8af387
Compare
So we don't need to set z-index in all the elements, creating the stacking context for the inner blocks, for example.
a8af387
to
0ae6273
Compare
bbcf05a
to
4b67126
Compare
@aaronrobertshaw, could this be related to the way it works when using the code editor mode? I could reproduce the same, but it seems it doesn't change the blocks when we are in the code editor mode. If we are in the visual mode and we edit anything and save, it changes properly, even if it's on the first try. |
Good point. I'll give it a bit more of a test. We'll also need to ensure that it is migrated correctly if patterns containing a deprecated version of the cover block are inserted. |
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.
Thanks for updating the deprecation fixtures @renatho 💪
That's a lot of files! 😅
Unfortunately, it looks like a large number shouldn't have needed changes.
- All the non-deprecation-related fixtures for the cover block need to be updated to the latest markup structure
I'm sorry I wasn't clearer with this comment in my last review.
All the source fixtures for deprecations e.g. *_deprecated-#.html
should remain as before. These fixtures are supposed to cover the deprecated versions of the block, as the were when they were deprecated.
Only the source fixtures for the current version of the block needed to be updated to the latest markup structure. These are all the .html
files that don't have __deprecated-#
in their name.
- After the above fixture updates, regenerating the fixtures should succeed and the result should be something like past deprecation's serialized HTML being updated to the correct structure.
With the source fixtures being correct, regenerating the fixtures would mean that the _deprecated-#.serialized.html
files all get updated showing they successfully migrate to the latest version i.e. with the wrapper's class (if it's kept) and the reordered inner elements as appropriate.
It might not seem like it but I don't think this PR is that far off. The deprecation itself seems ok, we just need to sort out the fixtures and the CSS approach.
I'd recommend to iterate on the CSS first as the possible removal of the need for a new CSS class would reduce the number of deprecation fixtures requiring change. Doing it the other way around would likely create unnecessary rework.
Thanks again for all your hard work and patience here @renatho 🙇
c108205
to
3369f0f
Compare
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 testing great for me so far, nice work both of you on honing in on the deprecation!
✅ Cover block continues to work as expected with a nested Navigation block, and the modal not erroneously displaying other Cover blocks over the top of it
✅ Double-checked that Group block variations still work correctly (that the previous regression wasn't introducde)
✅ Old Cover blocks render correctly on the site frontend as far as I can tell
✅ Old Cover blocks migrate correctly in the editor
Overall I like the approach here of using a different DOM order and removing the z-index
es. In general where possible I like it when we can avoid adding deprecations as we've already got a lot for this block and it can be hard to reason about. But in this case, I think re-ordering and removing the z-index
rules makes it worth it 👍
I see the mobile tests are still failing and will need an update. I left a couple of tiny comments. What else is there left to do before this is ready for a final review? (I see Aaron listed some above, but I thought I'd double check) Happy to keep testing next week!
@@ -95,17 +94,11 @@ | |||
} | |||
|
|||
.wp-block-cover__inner-container { | |||
position: relative; // Needed after the v14 deprecation.. |
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.
Tiny nit: can we explain why it's needed? The deprecations can be hard to understand, so if I read this comment I'd need to go looking to figure it out. Alternately, we could remove the comment if an explanation isn't necessary.
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.
Improved as part of this commit: f0640db
Thanks for the suggestion!
/* When the `.wp-block-cover__inner-container` comes right after the | ||
`.wp-block-cover__background` , it means that it's using the new HTML | ||
structure or that it's using the color background or gradient (even in | ||
the deprecated version). In the last option we also don't need the z-index | ||
because the elements are in the expected order. */ |
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.
Should we use //
comments so that the this comment doesn't get included in the built CSS?
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.
The problem is that it's a comment in the middle of the selector.
But I moved it and although complex, I hope that's clear enough. I also added another comment in the save.js
just to make sure we don't break anything accidentally.
I forgot to add in my previous comment — I looked and compared these and the deprecation's |
04f1c95
to
f0640db
Compare
580c590
to
99aa8f9
Compare
I fixed the React Native tests: It seems all the tests are passing now, but when I run the
I see it. I investigated it, and solved it with this commit: 330fabe Basically, this PR changed it but didn't update the deprecated block attributes. |
From memory, this is due to the way the deprecation attribute objects are created i.e. spreading the previous version's attributes then adding anything, resulting in a different order. There are a few options:
|
Thanks for laying that out! I'd go for either 1 or 3 so that the next person who runs the command to update fixtures isn't confused as to why there are changes to those files. If it improves readability to not worry about dealing with option 1, then option 3 could be the simplest path forward? |
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.
Thanks for the continued iteration here @renatho and the additional reviews @andrewserong.
I see it. I investigated it, and solved it with this commit: 330fabe
Basically, this PR changed it but didn't update the deprecated block attributes.
Nice work isolating that. I did mean to link that PR as a thread for you to follow, sorry.
I think we still have an issue though with the deprecation.
Note in the PR you linked that it did two things:
- Altered the block's
alt
attribute - Created a deprecation:
v13
That deprecation (v13
) needed to migrate the previous version of the block. The change to the alt
attribute definition was for (at that time) the current block version not the previous one.
So in other words, that PR "didn't miss anything" in relation to the attributes.
The error was introduced in this PR when it didn't include the updated alt
attribute definition to migrate the previous version to the latest. With the latest commits, we've swapped one problem for another.
The v13
deprecation now includes the updated alt
attribute definition when it shouldn't. The result would be blocks that should have been migrated by that deprecation will lose their custom alt text.
All this nuance, is a big part of why block deprecations are especially tricky to work with. The good news is, you're nearly there and the next deprecation is going to seem simple after wrestling the Cover block into submission 💪 .
Regarding the fixtures' parsed attributes being reordered, it appears that you should be fine to commit those. The order of attributes in these files already doesn't match the actual real block's when parsed but I don't think that should have any consequence.
330fabe
to
ce1399b
Compare
Hm! Good catch!
Yeah! It definitely seems tricky. Especially because we need to investigate the history of the block to deprecate it correctly. Thank you for all the learning here! Next time when I need to do it, it will be easier with a little more knowledge! I removed the previous commit: 330fabe So the new version of the
Commit here: ce1399b |
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.
At first glance I thought we'd made it to the finish line. Unfortunately, it looks like there's one small issue around the updates to the native tests and their related snaps.
I've left inline comments for those below. Once they are taken care of, we should be ready to merge 🤞
Especially because we need to investigate the history of the block to deprecate it correctly.
This isn't the case in my experience.
The majority of the issues we hit here were due to not working from the current block's attribute and support definitions etc. This commit shows the new deprecation worked from the last deprecation not the current block.
The other complicating factor was it not being intuitive as to how to update the deprecation fixtures correctly.
So to me, the "historical dig" was to just confirm where and when the deprecation went off the rails.
packages/block-library/src/cover/test/__snapshots__/edit.native.js.snap
Outdated
Show resolved
Hide resolved
92cc116
to
62d63b6
Compare
62d63b6
to
689d9e6
Compare
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.
Nice work @renatho, thanks for the determination to stick with this 🙇
This PR is looking good and testing well for me.
✅ Unit tests are passing
✅ Fixtures and deprecations look good
✅ Cover block is rendering as expected both before and after migration
✅ Didn't spot any regressions around the original issue with nav block overlays
Given the bumps in the road getting here, I think it would be prudent to get a fresh second set of eyes on this before merging. (cc @andrewserong when you have the time)
From my end though, this gets a ✅ as good to go.
Thanks for the ping @aaronrobertshaw and for all the detailed reviews here. I'll give it a review in the next few hours! |
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 testing nicely for me, too, I did a couple of other random smoke tests of things related to z-indexes and haven't run into any issues!
✅ Cover blocks with nested Navigation blocks are working as expected before and after applying this PR
✅ Navigation block overlays appear to work correctly in the post and site editors and the site frontend
✅ Deprecations appear to apply correctly
✅ Other configurations (e.g. video backgrounds, rounded borders) work correctly
✅ Sticky Group blocks within Cover blocks work just as on trunk
✅ Sticky Group blocks outside of Cover blocks work just as on trunk
✅ Deprecations and updated fixtures and tests look good as far as I can tell
Nice work persevering with this one @renatho, this LGTM! 🚀
Looks like we're all happy with this, so I'll merge it in. Thanks again for all the work here, both of you! |
Thanks for getting this one merged @andrewserong 🚀 |
* Remove not used variable * Change the order of the elements to the expected layers order So we don't need to set z-index in all the elements, creating the stacking context for the inner blocks, for example. * Update z-index styles to be applied only for backward compatibility * Add position relative to keep inner content on the top * Fix spinner position to be over the overlay * Add new fixture * Update cover fixtures * Update deprecation to match last update from trunk * Add class to the editor * Remove class in favor of a new approach checking the children * Use styles only on frontend for backward compatibility * Fix loading state * Revert "Update cover fixtures" This reverts commit 0ae6273. * Fix deprecations and fixtures * Revert "Add the has-modal-open to the editor reproducing the same behavior of the frontend" This reverts commit 64c14d3. * Improve documentation comments in the code * Fix native tests * Update snapshots * Fix order of the properties on the generated fixtures * Add alt attribute as part of the attributes changed in the previous version --------- Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com> Co-authored-by: renatho <renathoc@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
What?
This is an improved solution for this original PR: #66093
As part of this PR, I also thought of removing this effect that adds the
has-modal-open
in the editor because that wouldn't be needed for this purpose anymore. But thinking more, I kept it to keep the consistency there between the frontend and the editor.Why?
To improve the solution and eliminate the dependencies between Cover and Navigation blocks (the class that Navigation adds being used in the Cover styles).
More context starting from this comment in the thread.
How?
It deprecates the current version of the Cover block, changing the order of the elements, and removing the
z-index
of them.It continues using the
has-modal-open
class for backward compatibility (solution introduced in #66093), but when the code is updated it's not used anymore (after the save).Testing Instructions
Screenshots or screencast
Screen.Recording.2024-10-14.at.11.28.51.mp4
Since I continued seeing the same result in my tests, I reused the same video from #66093 just to illustrate the tests.