Skip to content
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

Replace using BroadcastChannel by injecting error message into error templates #104

Merged
merged 7 commits into from
Nov 6, 2018

Conversation

miina
Copy link
Contributor

@miina miina commented Oct 31, 2018

Fixes #86.

Adds placeholder tag for error details and replaces using BroadcastChanel.

};

let body = text.replace( /<!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, errorMessages.error );
body = body.replace( /<!--WP_SERVICE_WORKER_ERROR_DETAILS-->/, errorText );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter Should we have a placeholder text here in case there are no details for the error? For example No details received for the error or something similar?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. I don't think so, since if the details element is used then it would be expanded to find no additional details. The problem seems to be that the container element needs to be omitted if there is no error message, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, I had the thought that for consistency it would always be good to display the details even if there are no details -- to state explicitly there are no details so that it would be clear there were no details. Otherwise perhaps the user wouldn't know that no details were found.

If you think it's better to just not display the details at all then we can do that instead. Thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better for now to just omit the details entirely if there is no error message detected.

But I see that this presumes that the details isn't already present in the document.

return caches.match( ERROR_500_BODY_FRAGMENT_URL );
}

return response.text().then( function( errorText ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is duplicated in the offline commenting section.

@miina miina changed the title [WIP] Replace using BroadcastChannel. Replace using BroadcastChannel. Nov 1, 2018
}
</script>
<?php wp_print_service_worker_error_details_script( 'renderErrorDetails' ); ?>
<iframe style="width:100%;" srcdoc="<?php wp_service_worker_error_details_placeholder(); ?>"></iframe>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wp_service_worker_error_details_placeholder() won't work so well here because if trying to access the error page directly then you'd get:

<iframe style="width:100%;" srcdoc="<!--WP_SERVICE_WORKER_ERROR_DETAILS-->"></iframe>

That seems like it would be an HTML parse error for some parsers.

channel.close();
}, 30 * 1000 );
let body = text.replace( /<!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, errorMessages.error );
body = body.replace( /<!--WP_SERVICE_WORKER_ERROR_DETAILS-->/, errorText );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this would need to get encoded in order to be able to appear in an HTML attribute. If the errorText contains markup (as it is expected to) then it will likely break the srcdoc attribute.

}
</script>
<?php wp_print_service_worker_error_details_script( 'renderErrorDetails' ); ?>
<iframe style="width:100%;" srcdoc="<?php wp_service_worker_error_details_placeholder(); ?>"></iframe>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something else to consider is that srcdoc is not supported by all browsers. So perhaps it would make more sense to encode the errorText as an HTML data URI and then populate the src instead.

};

let body = text.replace( /<!--WP_SERVICE_WORKER_ERROR_MESSAGE-->/, errorMessages.error );
body = body.replace( /<!--WP_SERVICE_WORKER_ERROR_DETAILS-->/, errorText );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better for now to just omit the details entirely if there is no error message detected.

But I see that this presumes that the details isn't already present in the document.

wp-includes/service-workers.php Outdated Show resolved Hide resolved
@westonruter westonruter changed the title Replace using BroadcastChannel. Replace using BroadcastChannel by injecting error message into error templates Nov 6, 2018
@westonruter
Copy link
Collaborator

I've updated the theme to use these updated functions: westonruter/twentyseventeen-westonson#14

@westonruter westonruter added this to the 0.2 milestone Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reconsider use of JavaScript to inject 500 error details
2 participants