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

Infinite number of core/navigation-link variations upon many locale switch #59300

Closed
dd32 opened this issue Feb 23, 2024 · 5 comments
Closed
Labels
[Block] Navigation Link Affects the Navigation Link Block [Type] Bug An existing feature does not function as intended [Type] Performance Related to performance efforts

Comments

@dd32
Copy link
Member

dd32 commented Feb 23, 2024

Description

When WordPress switches between locales, part of this involves re-registering the post types as the $labels has changed.

The core/navigation-link block is hooked to registered_post_type which is fired as part of this re-registration, to add a new variation to the link of the Post type.

Unfortunately, there's no check to see if the variation already exists before adding it.
When a script is switching between locales often (As is done on WordPress.org in some places), this causes the block to gain an infinite number of vatiations until it runs out of memory.

For most sites which switch the locale once, maybe twice, this isn't an issue, and will probably never be noticed.

This was noticed within a script which switched between ~200 locales, and processed ~1800 posts. It started running out of memory after as few less than 10 posts.

(note: This also applies to the registered_taxonomy hook)

Step-by-step reproduction instructions

The simplest way to visualise this, is to run the following code, and observe the output. The memory usage will increase and the number of variations will too.

while ( true ) {
	$i++;
	switch_to_locale( 'en_GB' );
	if ( $i % 25 == 0 ) {
		echo "Iteration " . $i . ' ';
		echo size_format( memory_get_usage() ) . ' ';
		echo 'Registered variations for core/navigation-link: ' . count( WP_Block_Type_Registry::get_instance()->get_registered( 'core/navigation-link' )->variations );
		echo "\n";
	}
	restore_current_locale();
}

Screenshots, screen recording, code snippet

example output of the above script:

Screenshot 2024-02-23 at 2 13 44 pm

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@dd32 dd32 added the [Type] Bug An existing feature does not function as intended label Feb 23, 2024
@t-hamano t-hamano added [Type] Performance Related to performance efforts [Block] Navigation Link Affects the Navigation Link Block labels Feb 23, 2024
dd32 added a commit to WordPress/pattern-directory that referenced this issue Feb 23, 2024
This is the root cause that caused #620, and is now tracked upstream as WordPress/gutenberg#59300
@Mamaduka
Copy link
Member

I think the issue will be fixed in WP 6.5. See #58389. cc @gaambo

@gaambo
Copy link
Contributor

gaambo commented Feb 23, 2024

Yep, that should be fixed in Gutenberg 17.7 and therefore in WordPress 6.5, because the registered_post_type/registered_taxonomy hooks are not used anymore.
@dd32 Which setup/versions are you using?

It's a good thing the variation_callback was introduced, and we switched to that. Seems the earlier approach with those two hooks would have led to a lot of problems once in core.

@dd32
Copy link
Member Author

dd32 commented Feb 23, 2024

I think the issue will be fixed in WP 6.5. See #58389. cc @gaambo

Damnit. You're right; I've just rechecked and the site in question was running Gutenberg 17.6, not 17.7 where it's fixed 🤦
This has been an issue for the past 3 weeks and I'd only just figured out where it was coming from..

@dd32 dd32 closed this as completed Feb 23, 2024
@Mamaduka
Copy link
Member

Thanks for the confirmation, @dd32!

It's good to know that using registered_post_type/registered_taxonomy could have performance implications for similar cases.

@dd32
Copy link
Member Author

dd32 commented Feb 23, 2024

Thanks @Mamaduka and @gaambo for that, I can't believe I missed it was outdated! But I'm happy that it's already fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Link Affects the Navigation Link Block [Type] Bug An existing feature does not function as intended [Type] Performance Related to performance efforts
Projects
None yet
Development

No branches or pull requests

4 participants