-
Notifications
You must be signed in to change notification settings - Fork 381
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
Prevent registration of deprecated AMP blocks that are not used in post #5575
Prevent registration of deprecated AMP blocks that are not used in post #5575
Conversation
Plugin builds for 179f931 are ready 🛎️!
|
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.
@pierlon Aside from the one typo this looks great and works as expected for my locally.
@pierlon @westonruter While this is working great, I wonder about the approach to this notice with the plugin sidebar, which I have in progress (and whose branch touches most of these same files, some in significant ways). Do you think we'd want to keep this notice as is or move it into the sidebar? If in the sidebar, we could perhaps implement a secondary badge on this button, maybe an exclamation point or something below the number (cc @jwold) What do you think? Even if some of this becomes obsolete soon, I suggest we merge it anyway in case the sidebar takes longer than expected. I can handle merging these changes back into my branch. |
Yea the current method of displaying notices in the editor is a bit of a hack; if the Block Annotations API was stable I think that would be the best option to display the notice. I'm open to seeing how it would be displayed in the sidebar but I'd say we can merge this anyway and see how it looks when the sidebar comes to fruition. |
'amp/amp-springboard-player', | ||
'amp/amp-timeago', | ||
]; | ||
|
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.
@pierlon On second look, I'm questioning whether it's necessary to move the hardcoded block names into PHP and handle ampBlocks
and ampBlocksInUse
here. ampBlocksInUse
could be achieved in the editor, maybe by applying withSelect
to the new higher-order component and filtering select( 'core/block-editor' ).getBlocks()
. This should be fine performancewise because I imagine it's rare to have many AMP blocks on a page, and getBlocks
is memoized.
With future deprecation in mind, I think it might make more sense to focus on refactoring on the JS side to make these blocks easy to delete when the time comes. I'd break the blocks into a module of their own with a single entry point in the editor JS (or put them in their own JS file, but that might be going farther than needed). Do you think this would work? Then we wouldn't have to make the PHP side of the plugin aware of these blocks that we are deprecating, which seems a bit like a step in the wrong direction.
import { __ } from '@wordpress/i18n'; | ||
import { Notice } from '@wordpress/components'; | ||
|
||
export default createHigherOrderComponent( |
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.
See my other comment. I would apply withSelect
with a JS version of ampBlocksInUse
here.
I wonder if we need to worry about it now? What's the behavior when we remove the block entirely? The editor will say the block is unrecognized and prompt to convert to a Custom HTML block, right? Then the AMP content in the block will continue to work exactly the same since it's just static content, right? |
ed28905
to
a7d809d
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5575 +/- ##
==========================================
Coverage 75.12% 75.13%
- Complexity 5645 5647 +2
==========================================
Files 210 210
Lines 16955 16961 +6
==========================================
+ Hits 12737 12743 +6
Misses 4218 4218
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Co-authored-by: John Watkins <[email protected]>
a7d809d
to
99574bf
Compare
@westonruter Yes, the option to convert to a Custom HTML block is provided. My main concern is informing the user that the block is no longer supported by the plugin. Do you think that the generic warning provided by Gutenberg is enough? Here's what it looks like, for example: |
Yeah, it's a good question, and it's hard to know without having data. What about if we omit having any special notice for now (and just have the generic Gutenberg warning). And then if beta testers report it being a problem, we then introduce a deprecation notice to let them know that the blocks have gone away? |
I'm on board with that, will adapt the PR. |
@westonruter I've updated the PR description to align with the new changes and requesting a review. |
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.
Good work.
*/ | ||
public function get_amp_blocks_in_use() { | ||
// Normalize the AMP block names to include the `amp/` namespace. | ||
$amp_blocks = substr_replace( AMP_Editor_Blocks::AMP_BLOCKS, 'amp/', 0, 0 ); |
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.
TIL: substr_replace()
with an array.
Summary
Fixes #4556
When in Standard Mode, only AMP-specific blocks found within the post are registered for use in the editor. This should help to curb the usage of the other AMP blocks as they will no longer be supported and are to be deprecated.
Once the blocks are removed from the plugin, users will see a warning message from the editor informing them that the block is not supported:
As noted in #5575 (comment), we could introduce a deprecation notice if users report it being a problem.
Checklist