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

Try: JS Console warning for when in Quirks Mode #12575

Merged
merged 4 commits into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,25 +567,3 @@ function gutenberg_add_responsive_body_class( $classes ) {
}

add_filter( 'body_class', 'gutenberg_add_responsive_body_class' );

/**
* Prints JavaScript to detect whether the browser is in standards mode or not.
*
* @since 4.6
*/
function gutenberg_detect_quirks_mode() {
?>
<script type="text/javascript">
document.addEventListener( 'DOMContentLoaded', function() {
try {
var documentMode = document.compatMode==='CSS1Compat'?'Standards':'Quirks';
if (documentMode != 'Standards' ) {
console.log( '[Warning] Your browser is using Quirks Mode. \nThis can cause rendering issues such as blocks overlaying meta boxes in the editor. Quirks Mode can be triggered by PHP errors or HTML code appearing before the opening <!DOCTYPE html>. Try checking the raw page source or your site\'s PHP error log and resolving errors there, removing any HTML before the doctype, or disabling plugins.' );
}
} catch( e ) { }
} );
</script>
<?php
}
add_action( 'admin_print_scripts-post.php', 'gutenberg_detect_quirks_mode' );
add_action( 'admin_print_scripts-post-new.php', 'gutenberg_detect_quirks_mode' );
9 changes: 9 additions & 0 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export function initializeEditor( id, postType, postId, settings, initialEdits )

registerCoreBlocks();

// Show a console log warning if the browser is not in Standards rendering mode.
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any particular reason for the try/catch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Old habit, I suppose, for any variable that I worry won't be supported by a particular browser.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really see anything that would break in this code, so I'd just leave them out if possible.

const documentMode = document.compatMode === 'CSS1Compat' ? 'Standards' : 'Quirks';
if ( documentMode !== 'Standards' ) {
// eslint-disable-next-line no-console
console.warn( '[Warning] Your browser is using Quirks Mode. \nThis can cause rendering issues such as blocks overlaying meta boxes in the editor. Quirks Mode can be triggered by PHP errors or HTML code appearing before the opening <!DOCTYPE html>. Try checking the raw page source or your site\'s PHP error log and resolving errors there, removing any HTML before the doctype, or disabling plugins.' );
}
} catch ( e ) { }

dispatch( 'core/nux' ).triggerGuide( [
'core/editor.inserter',
'core/editor.settings',
Expand Down