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

Reconsider use of JavaScript to inject 500 error details #86

Closed
westonruter opened this issue Oct 12, 2018 · 1 comment · Fixed by #104
Closed

Reconsider use of JavaScript to inject 500 error details #86

westonruter opened this issue Oct 12, 2018 · 1 comment · Fixed by #104
Milestone

Comments

@westonruter
Copy link
Collaborator

A 500.php template currently needs to include the following to display any 500 error that was returned from the server:

<details id="error-details" hidden>
	<summary><?php esc_html_e( 'More details', 'twentyseventeen-westonson' ); ?></summary>
	<iframe srcdoc=""></iframe>
	<script>
	function renderErrorDetails( data ) {
		if ( data.bodyText.trim().length ) {
			const details = document.getElementById( 'error-details' );
			details.querySelector( 'iframe' ).srcdoc = data.bodyText;
			details.hidden = false;
		}
	}
	</script>
	<?php wp_print_service_worker_error_details_script( 'renderErrorDetails' ); ?>
</details>

However, this currently depends on BroadcastChannel to send the message from the service worker to the client after the page has loaded:

https://github.com/xwp/pwa-wp/blob/57b295c646bfae63f78c3d735fbc37762709fca0/wp-includes/js/service-worker-error-response-handling.js#L11-L31

It would seem more straightforward to instead inject the error messages directly into the details element when the 500 error is being constructed. This could be done done with streams or more simply it could be done just by reading the body of the 500 error response and injecting it straight away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants