-
Notifications
You must be signed in to change notification settings - Fork 100
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
Error template placeholder HTML comments can be stripped out by minifiers #709
Comments
@westonruter I was working upon this and tried the following idea: function wp_service_worker_error_message_placeholder() {
// echo '<p><!--WP_SERVICE_WORKER_ERROR_MESSAGE--></p>';
echo '<p><span id="wp-service-worker-error-message"></span></p>';
} and replace whole span element with following reges /[<]span id="wp-service-worker-error-message">(\s)*[<]\/span>/ For error message details: function wp_service_worker_error_details_template( $output = '' ) {
if ( empty( $output ) ) {
$output = '<details id="error-details"><summary>' . esc_html__( 'More Details', 'pwa' ) . '</summary>{{{error_details_iframe}}}</details>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Variable includes iframe tag.
}
// echo '<!--WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN-->';
echo '<span id="wp-service-worker-error-template-begin"></span>';
echo wp_kses_post( $output );
// echo '<!--WP_SERVICE_WORKER_ERROR_TEMPLATE_END-->';
echo '<span id="wp-service-worker-error-template-end"></span>';
} and replace whole span element with following reges /([<]span id="wp-service-worker-error-template-begin">(\s)*[<]\/span>)((?:.|\n)+?)([<]span id="wp-service-worker-error-template-end">(\s)*[<]\/span>)/ If you some another ideas please share and let me know your thoughts on the above method if it can work in our current scenerio. |
I just realized that we're using Mustache-like tokens in So that could be: function wp_service_worker_error_message_placeholder() {
echo '<p>{{{WP_SERVICE_WORKER_ERROR_MESSAGE}}}</p>';
} And: function wp_service_worker_error_details_template( $output = '' ) {
if ( empty( $output ) ) {
$output = '<details id="error-details"><summary>' . esc_html__( 'More Details', 'pwa' ) . '</summary>{{{error_details_iframe}}}</details>'; // phpcs:ignore WordPressVIPMinimum.Security.Mustache.OutputNotation -- Variable includes iframe tag.
}
echo '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_BEGIN}}}';
echo wp_kses_post( $output );
echo '{{{WP_SERVICE_WORKER_ERROR_TEMPLATE_END}}}';
} |
I found moustache template tokens more suitable in our use case. So using mustache- tokens at the place of HTML tags. |
As mentioned by @stack-exchange in a gist comment:
The issue is the AMP Optimizer's
MinifyHtml
transformer which strips out HTML comments. This will also be an issue with other optimization plugins. Therefore, instead ofwp_service_worker_error_message_placeholder()
andwp_service_worker_error_details_template()
outputting HTML comments, they should instead output HTML elements, identified by an ID.pwa-wp/wp-includes/template.php
Lines 168 to 173 in a1f9125
pwa-wp/wp-includes/template.php
Lines 154 to 166 in a1f9125
Note this will make the regex a bit more complicated here:
pwa-wp/wp-includes/js/service-worker-navigation-routing.js
Line 75 in d415cb2
The text was updated successfully, but these errors were encountered: