-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add function which checks if content of post is empty #2536
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2536 +/- ##
==========================================
- Coverage 30.1% 27.12% -2.99%
==========================================
Files 174 159 -15
Lines 5288 4911 -377
Branches 907 818 -89
==========================================
- Hits 1592 1332 -260
+ Misses 3132 3036 -96
+ Partials 564 543 -21
Continue to review full report at Codecov.
|
I don't know if I missing something here, but I expected the "publish" button to stay disabled when I click on the placeholder (creating a first empty text block). In other words, I expected this <!-- wp:core/paragraph -->
<p></p>
<!-- /wp:core/paragraph --> to be considered as empty content |
* @param {Object} state Global application state | ||
* @return {Boolean} Whether it's considered empty | ||
*/ | ||
export function isEmptyContent( state ) { |
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.
Can we add some unit tests?
@@ -12,6 +12,9 @@ import { serialize, getBlockType } from '@wordpress/blocks'; | |||
import { __ } from '@wordpress/i18n'; | |||
import { addQueryArgs } from '@wordpress/url'; | |||
|
|||
const REGEXP_EMPTY_CONTENT = /^<!--(.)*>(\s)*<p[^>]*>( |\s|<br[^>]*>)*<\/p>(\s)(.)*-->$/mg; |
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.
.*
are prone to greediness, which results in issues like this:
We should also note the case of dynamic (server-rendered) blocks, which intentionally do not have any content in the post editor. Take the "Latest Posts" block for example, which saves itself as:
A post with this block should not be considered empty. |
Fixes #1501.
I added a function which checks whether the content of a post is considered empty.
Another bug occurred. But that is probably related with #1240.
Steps to reproduce:
I expect content to mark as dirty immediately and 'Save' button should be shown. But it happens after clicking next to the block.
All local tests ran OK.