bobbingwide / written

An experimental FSE theme to replace Genesis-hm
GNU General Public License v3.0
0 stars 0 forks source link

Navigation menu in header doesn't respond when Overlay Menu Mobile is set #19

Open bobbingwide opened 1 year ago

bobbingwide commented 1 year ago

In my local development environment( s.b/hm ) with WordPress 6.1 and Gutenberg 14.4.0 or 14.5.0 when I configured the navigation menu to use the 3 bar hamburger menu item I couldn't get it to display a menu.

In herbmiller.me it works.

I can't see any messages in the console. So what's different?

bobbingwide commented 1 year ago

In my local development environment I have two Navigation menus, dated 17th and 24th February. I don't have these in herbmiller.me

When I deleted the Navigation menu, the Site Editor complained that it was missing... it has been deleted. This is referred to by the Header template. In herbmiller.me the Header template includes the blocks for the navigation menu, not just a reference. It's pretty much the same as what I see in the parts/header.html file.

bobbingwide commented 1 year ago

Deactivating Gutenberg in s.b/hm resolved the problem. Updating Gutenberg to 14.5.0 on herbmiller.me didn't create the problem.

bobbingwide commented 1 year ago

It looks like a similar problem as originally reported. I commented out the test as below.

function gutenberg_block_type_metadata_view_script( $settings, $metadata ) {
    bw_trace2();
    bw_trace2( gutenberg_dir_path(), "GBDIRPATH", false );
    if (
        ! isset( $metadata['viewScript'] ) ||
        ! empty( $settings['view_script'] ) ||
        ! isset( $metadata['file'] ) /* ||
        ! str_starts_with( $metadata['file'], gutenberg_dir_path() ) */
    ) {

        return $settings;
    }

$metadata['file'] is "C:/apache/htdocs/bigram/wp-includes/blocks/navigation/block.json"

GBDIRPATH is C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg/

The scripts were enqueued but with the wrong path.

<script src='https://s.b/bigram/wp-content/plugins/gutenberg/C:/apache/htdocs/wordpress/wp-content/plugins/gutenberg/build/block-library/blocks/navigation/view.min.js?ver=d8b4322c6e0cdc1fc353' id='wp-block-navigation-view-js'></script>
<script src='https://s.b/bigram/wp-content/plugins/gutenberg/C:/apache/htdocs/wordpress/wp-content/plugins/gutenberg/build/block-library/blocks/navigation/view-modal.min.js?ver=a308a84545a768017eeb' id='wp-block-navigation-view-modal-js'></script>

But this time, it wasn't just the directory separators but the fact that Gutenberg wants to enqueue the file from a different folder.

.... but that doesn't explain why it's working on my Linux hosting

bobbingwide commented 1 year ago

On live sites the JS is correctly enqueued from Gutenberg

<script src='https://seriouslybonkers.com/wp-content/plugins/gutenberg/build/block-library/blocks/navigation/view.min.js?ver=d8b4322c6e0cdc1fc353' id='wp-block-navigation-view-js'></script>
<script src='https://seriouslybonkers.com/wp-content/plugins/gutenberg/build/block-library/blocks/navigation/view-modal.min.js?ver=a308a84545a768017eeb' id='wp-block-navigation-view-modal-js'></script>
bobbingwide commented 1 year ago

gutenberg_block_type_metadata_view_script() is called twice when metadata['viewScript'] is set to file:./view-modal.min.js The first time it's for the WordPress core version: C:/apache/htdocs/wp55/wp-includes/blocks/navigation/block.json

When it's for Gutenberg the value of $metadata['file'] is

C:/apache/htdocs/wp55/wp-content/plugins/gutenberg/build/block-library/blocks/navigation/block.json

gutenberg_dir_path() returns

C:\apache\htdocs\wp55\wp-content\plugins\gutenberg/

realpath() of this is

C:\apache\htdocs\wp55\wp-content\plugins\gutenberg

To avoid the early return we need to change

! str_starts_with( $metadata['file'], gutenberg_dir_path() )

to

! str_starts_with( wp_normalize_path( $metadata['file'] ), wp_normalize_path( realpath( gutenberg_dir_path() ) ) )

Then change

gutenberg_url( str_replace( gutenberg_dir_path(), '', $view_script_path ) ),

to

gutenberg_url( str_replace( wp_normalize_path( realpath( gutenberg_dir_path())), '', wp_normalize_path( $view_script_path ) ) ),