-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Blocks: Stop showing errors and warnings when blocks gets successfully updated from deprecated version #16862
Conversation
@youknowriad and @mcsf - I'd love to hear your thoughts on the general direction proposed in this commit: 7be5763. |
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 end result is satisfying but I have some concerns about the "logger" implementation and the fact that we need a stateful object.
What if instead we just change the result of the validation functions from being a boolean with messaged logged to being an object containing a status and messages and let the caller decide what to do with these?
I'm not happy about that as well. This was my biggest concern from the beginning but I wanted to focus on the experience first. I considered something similar to what you described. The biggest concern is that /**
* @param {string|Object} blockTypeOrName Block type.
* @param {Object} attributes Parsed block attributes.
* @param {string} originalBlockContent Original block content.
* @param {?Object} options Additional config options.
* @param {?Boolean} options.detailedReport Return all errors and warnings.
*
* @return {boolean|Object} Whether block is valid. When options.detailedReport
* is set to true, this function will return an object with
* the list of errors or warnings and isValid property.
*/
export function isValidBlockContent( blockTypeOrName, attributes, originalBlockContent, { detailedReport = false } ) {
const isValid = true; // or false
if ( detailedReport ) {
return {
isValid,
logs,
};
}
return isValid;
} |
@gziolo We could use another function internally and make |
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 that you're working on this.
-
I agree with what's discussed around avoiding statefulness if practical.
-
The flow in the log can be a bit awkward depending on what is valid and invalid. Steps to repro:
2.1. Change the demo content by adding a bogus data attribute to the first DIV, like so:
diff --git a/post-content.php b/post-content.php
index 032c4ad10..7f3621ada 100644
--- a/post-content.php
+++ b/post-content.php
@@ -7,7 +7,7 @@
?>
<!-- wp:cover {"url":"https://cldup.com/Fz-ASbo2s3.jpg","className":"alignwide"} -->
-<div class="wp-block-cover has-background-dim alignwide" style="background-image:url(https://cldup.com/Fz-ASbo2s3.jpg)"><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
+<div class="wp-block-cover has-background-dim alignwide" data-foo="bar" style="background-image:url(https://cldup.com/Fz-ASbo2s3.jpg)"><div class="wp-block-cover__inner-container"><!-- wp:paragraph {"align":"center","placeholder":"Write title…","fontSize":"large"} -->
<p style="text-align:center" class="has-large-font-size"><?php _e( 'Of Mountains & Printing Presses', 'gutenberg' ); ?></p>
<!-- /wp:paragraph --></div></div>
<!-- /wp:cover -->
2.2. This will break the opening Cover block of the demo.
2.3. Open the demo post. Notice how the first line logged reads Block successfully updated for core/paragraph
, which refers to the P tag inside the broken Cover block. The following lines are errors logged for the invalid Cover block as a whole.
2.4. The first line, about core/paragraph
, should probably not be there, since in the end we didn't get a new Paragraph block in the block list, we only get an invalid Cover block.
7be5763
to
ee8519a
Compare
I followed this recommendation from @youknowriad and introduced an internal method
I can reproduce that. Well, technically speaking it's correct because we validate/migrate nested blocks first. I understand this might be confusing. I guess, we could resolve that but I don't see it as a blocker since the proposed solution is way much better than what we have as of today. Anyway, I will look into a nice fix tomorrow :) |
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.
Looks great! As you pointed out, any bits such as #16862 (comment) is something we can figure out later.
A recent discussion I saw raised this point, should those messages show up in production? at what stage should they be shown? for the end-user, only errors are relevant right? |
I don't have strong feelings, either on or off on production is fine :) |
Since most users keep their console closed, what is the motivation for hiding the messages in production? Personally, I think they could be useful in assisting users experiencing issues. |
well for now they show when nothing is wrong, might emit only error ones? ones that can be actionable? |
Reducing noise sounds good. :) |
Description
This was something I wanted to tackle for quite some time. I decided to finally approach it when I worked on #16794 and I encountered this issue (#16794 (comment)):
This is how the same demo page behaves when loaded with this branch:
Instead of throwing scary warnings and errors, the proposed implementation only informs on Web Console that block was successfully updated to the latest version.
How has this been tested?
Screenshots
Types of changes
Checklist: