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

Use alternative to BroadcastChannel for sending server error to client 500 page #81

Closed
westonruter opened this issue Sep 23, 2018 · 2 comments
Milestone

Comments

@westonruter
Copy link
Collaborator

When a 500 error occurs, a 500 error template is served by the service worker. If there was an error message displayed on the response, the HTML is sent to the served 500 error page via BroadcastChannel:

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

However, this is not supported by browsers other than Chrome and Firefox: https://caniuse.com/#feat=broadcastchannel

We'll need to find an alternative. (Also the approach taken should be validated.)

Aside: We also need to prevent serving the 500 template when WordPress is actually rendering a response with a 500 status code, per #74.

@westonruter
Copy link
Collaborator Author

Actually, we don't need to send the error in a message at all. We can instead write the error message directly into the 500 error template response.

This would eliminate the need for wp_print_service_worker_error_details_script() and most of:

<?php if ( ! ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) ) : ?>
	<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>
<?php endif; ?>

Instead, there could be some token that is added to the template which is then replaced with the error when the service worker serves the response. There could be a token for encoding the error in an HTML attribute (for the iframe@srcdoc). Perhaps the token should be replaced with the entire populated details element, rather than just updating the iframe. We may not need to allow the markup to be modified to a large degree.

@westonruter
Copy link
Collaborator Author

Closing in favor of #86.

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

No branches or pull requests

1 participant