Add stylesheet information to validated URL screen#4026
Add stylesheet information to validated URL screen#4026westonruter merged 42 commits intodevelopfrom
Conversation
…e_document method Add tests for AMP_Content_Sanitizer, removing obsolete AMP_Test_World_Sanitizer
…alidation_Manager::get_validate_response_data()
…a to validate responses
…udget but still included Also improve message
| <?php | ||
| $origin_abbr_text = '?'; | ||
| if ( 'link_element' === $stylesheet['origin'] ) { | ||
| $origin_abbr_text = '<link …>'; // @todo Consider adding the basename of the CSS file. |
There was a problem hiding this comment.
Including the handle would be useful as well.
| .shaken-stylesheet { | ||
| display: block; | ||
| white-space: pre-wrap; | ||
| overflow-x: scroll; |
|
FYI: I used the branch for this PR to do the analysis of all themes on WordPress.org. |
There was a problem hiding this comment.
Looks good!
Hi @westonruter,
This is a huge improvement, having a UI for this. The percentage in the admin bar is great, also.
There's only one comment here related to logic. The rest are UI-related.
| } | ||
|
|
||
| $assets = AMP_Content_Sanitizer::sanitize_document( $dom, self::$sanitizer_classes, $args ); | ||
| $sanitization_results = AMP_Content_Sanitizer::sanitize_document( $dom, self::$sanitizer_classes, $args ); |
| if ( empty( $stylesheets ) ) { | ||
| printf( | ||
| '<p><em>%s</em></p>', | ||
| esc_html__( 'No stylesheet data available. Please try re-checking this URL.', 'amp' ) |
| <?php AMP_Validation_Error_Taxonomy::render_sources( $stylesheet['sources'] ); ?> | ||
| </dd> | ||
|
|
||
| <dt><?php esc_html_e( 'CSS Code', 'amp' ); ?></dt> |
| if ( $del_count > 0 ) { | ||
| printf( | ||
| '<p><label><input type="checkbox" class="show-removed-styles"> %s</label></p>', | ||
| esc_html__( 'Show styles removed during tree-shaking', 'amp' ) |
| const showRemovedStylesCheckbox = stylesheetDetailsElements.querySelector( '.show-removed-styles' ); | ||
| if ( showRemovedStylesCheckbox ) { | ||
| showRemovedStylesCheckbox.addEventListener( 'click', () => { | ||
| shakenStylesheetContainer.classList.toggle( 'removed-styles-shown', showRemovedStylesCheckbox.checked ); |
There was a problem hiding this comment.
This is working fine now with a hard refresh.
| <dt><?php esc_html_e( 'Original Markup', 'amp' ); ?></dt> | ||
| <dd><code class="stylesheet-origin-markup"><?php echo esc_html( $origin_html ); ?></code></dd> | ||
|
|
||
| <dt><?php esc_html_e( 'Sources', 'amp' ); ?></dt> |
| font-weight: bold; | ||
| text-align: right; | ||
| } | ||
|
|
| } | ||
|
|
||
| $css_usage_percentage = ceil( ( $total_size / $this->style_custom_cdata_spec['max_bytes'] ) * 100 ); | ||
| $menu_item_text = __( 'CSS Usage', 'amp' ) . ': '; |
| </button> | ||
| </td> | ||
| <td class="column-stylesheet_order"> | ||
| <?php echo (int) $row; ?> |
There was a problem hiding this comment.
$row is already an int here.
There was a problem hiding this comment.
Yes. This is done purely as a way to explicitly mark the variable as safe for printing. So it's an alternative to doing esc_html().
Co-Authored-By: Pierre Gordon <16200219+pierlon@users.noreply.github.com>
amedina
left a comment
There was a problem hiding this comment.
In the "Stylesheets" section part of the Validate URL screen, the status column can be seen as redundant. Since there is so much info on that table, I propose combining the Percentage column and the Status column into one. The semantics of the Status column can be conveyed by either just the color of the Percentage bar, or adding the Status symbol next to the Percentage bar.
amedina
left a comment
There was a problem hiding this comment.
Similarly, The Minified and Final Size columns can be combined, effectively removing another column and making the table less crowded. This can be done by Displaying Final Size (Minified %). For example: 220B (-40.5%).
<
Discussed offline. These two columns play an important role for developers. We will keep them and will further the discussion to devise improvements afterwards. |
amedina
left a comment
There was a problem hiding this comment.
Discussed comments offline. Ship it!
|
I should have added more tests. See #4175. |


















Summary
include_manifest_commentargument to the style sanitizer has been eliminated.wp amp validation check-url) includes the raw stylesheet information. To facilitate this, a newget_validate_response_datamethod has been added to the base sanitizer which is used during a validation response for sanitizers to augment the response with additional sanitizer-specific data (such as stylesheets).Fixes #2169.
Note 1: The work here was done within the architecture of the current codebase, which makes the implementation not as ideal as possible, especially for the newly added UI. This will be addressed when the UI is revamped to be more modern.
Note 2: The storage of the stylesheet data alongside the validation errors and the queried object are highlighting deficiencies of the
amp_validated_urlpost type data format and the API ofAMP_Validated_URL_Post_Type::store_validation_errors(). These will need to be addressed with a later refactor.See screenshots in comments below.
Todo
display:block)styleattributes and other style rules, add explanation for why:not(#_)shows up so much.meteror percentage usage column in Validated URL post list table.For Later
wp_add_inline_style(), like for Twenty Twenty. See Scripts and styles enqueued before wp_enqueue_scripts fail to get sources identified #4133.initdo not get sourcing information. Stylesheets registered atwp_default_styleslikewise are not identified. See Scripts and styles enqueued before wp_enqueue_scripts fail to get sources identified #4133.Checklist