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

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

Open
bobbingwide opened this issue Nov 14, 2022 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@bobbingwide
Copy link
Owner

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 bobbingwide added the bug Something isn't working label Nov 14, 2022
@bobbingwide bobbingwide self-assigned this Nov 14, 2022
@bobbingwide
Copy link
Owner Author

bobbingwide commented Nov 14, 2022

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
Copy link
Owner Author

bobbingwide commented Nov 14, 2022

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

@bobbingwide
Copy link
Owner Author

bobbingwide commented Nov 15, 2022

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
Copy link
Owner Author

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
Copy link
Owner Author

bobbingwide commented Nov 15, 2022

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 ) ) ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant