johnbillion / query-monitor

The developer tools panel for WordPress
https://querymonitor.com
GNU General Public License v2.0
1.58k stars 207 forks source link

Fatal error in QM_Output_Html_Assets::get_dependency_data #387

Open tomjn opened 5 years ago

tomjn commented 5 years ago

I'm unsure how this happened but I found it in my error logs, in v3.2.2:

Fatal error: Uncaught TypeError: Argument 1 passed to QM_Output_Html_Assets::get_dependency_data() must be an instance of _WP_Dependency, boolean given, called in /srv/www/tomjn.com/htdocs/wp-content/plugins/query-monitor/output/html/assets.php on line 149 and defined in /srv/www/tomjn.com/htdocs/wp-content/plugins/query-monitor/output/html/assets.php:175
Stack trace:
#0 /srv/www/tomjn.com/htdocs/wp-content/plugins/query-monitor/output/html/assets.php(149): QM_Output_Html_Assets->get_dependency_data(false, Object(WP_Styles), 'styles')
#1 /srv/www/tomjn.com/htdocs/wp-content/plugins/query-monitor/output/html/assets.php(119): QM_Output_Html_Assets->dependency_rows(Array, Object(WP_Styles), 'Footer', 'styles')
#2 /srv/www/tomjn.com/htdocs/wp-content/plugins/query-monitor/dispatchers/Html.php(197): QM_Output_Html_Assets->output()
#3 /srv/www/tomjn.com/htdocs/wp-includes/class-wp-hook.php(286): QM_Dispatcher_Html->dispatch('')
#4 /srv/www/tomjn.com/htdocs/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
in /srv/www/tomjn.com/htdocs/wp-content/plugins/query-monitor/output/html/assets.php on line 175
johnbillion commented 5 years ago

IIRC this can happen when a plugin deregisters a script very late on in the page load.

Can you narrow down which plugin or theme is causing the error to appear? Does the error appear more than once?

tomjn commented 5 years ago

On the frontend of my site it would appear to be jetpack_css, but that may be due to micro-optimising shenanigans I did

Here's the kludge I tested it with:

        protected function dependency_rows( array $handles, WP_Dependencies $dependencies, $label, $type ) {
                foreach ( $handles as $handle ) {

                        $dependency = $dependencies->query( $handle );
                        if ( is_user_logged_in() ) {
                                if ( is_bool( $dependency ) ) {
                                        wp_die( 'qm:"'.$handle.'"' );
                                }
                        }
                        list( $src, $host, $source, $local ) = $this->get_dependency_data( $dependency, $dependencies, $type );
tomjn commented 5 years ago
                            if ( is_bool( $dependency ) ) {
                                    continue;
                            }

This would fix the issue though it would be useful to know that something named jetpack_css was deregistered

johnbillion commented 5 years ago

Are you able to try out the develop branch of QM? I've refactored this entire panel, but the issue might still appear.

tomjn commented 5 years ago

hmmm this is in production so I'm not keen on installing node/npm/grunt/etc to build the develop branch.

To reproduce, I have this mu-plugin:

<?php

add_filter( 'jetpack_implode_frontend_css', '__return_false' );

add_action('wp_print_styles', 'tomjn_filter_scripts', 1000000);
add_action('wp_print_footer_scripts',  'tomjn_filter_scripts', 1000000);

function tomjn_filter_scripts(){
        wp_deregister_style('jetpack-widgets');
        wp_deregister_style('grunion.css'); // Grunion contact form
        wp_dequeue_style( 'jetpack-widget-social-icons-styles' );
        wp_dequeue_style( 'jetpack_css' );
        wp_deregister_style( 'jetpack_css' );
}

add_action( 'wp_enqueue_scripts', 'crunchify_enqueue_scripts_styles',100000000 );
function crunchify_enqueue_scripts_styles() {
     wp_dequeue_script( 'devicepx' );
}

Perhaps deregistering as well as dequeuing was a little overzealous 🤔

johnbillion commented 5 years ago

You don't need to build anything if you use the develop branch, the only thing that gets built in QM is the Sass, and that's currently committed directly to the repo too because I know people are using clones of the repo directly.

Thanks for that code block. I imagine the problem lies somewhere among the deregistering and dequeueing - I'll find some time over the next couple of weeks to take a look.

johnbillion commented 5 years ago

Gonna close this off, please do re-open if you can figure out what caused this or if you can reproduce. Cheers!

johnbillion commented 5 years ago

Oh wait, I should read my own comments before closing tickets. This is with me.