gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles throws a Fatal Error in certain conditions

Open BogdanUngureanu opened this issue 7 months ago • 4 comments

Description

In certain scenarios, get_post function returns null after the wp_insert_post function is called. Although the post is saved, it's assumed that it can be immediately accessed, which is not always true.

The line that triggers the fatal is this one: https://github.com/WordPress/gutenberg/blob/trunk/lib/class-wp-theme-json-resolver-gutenberg.php#L514

Step-by-step reproduction instructions

  1. No steps to reproduce it sadly, but it happens on hot paths

Screenshots, screen recording, code snippet

No response

Environment info

No response

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

  • [x] Yes

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

  • [x] Yes

Please confirm which theme type you used for testing.

  • [x] Block
  • [ ] Classic
  • [ ] Hybrid (e.g. classic with theme.json)
  • [ ] Not sure

BogdanUngureanu avatar May 19 '25 13:05 BogdanUngureanu

Thanks for the report.

Could you elaborate on what the certain scenarios are? Because there are many other places where get_post is executed after wp_insert_post. Does the problem only occur with the WP_Theme_JSON_Resolver::get_user_data_from_wp_global_styles method?

Example:

  • https://github.com/t-hamano/wordpress-develop/blob/33a612053d5db243ac928a99ccec41d6e2f8a80e/src/wp-admin/includes/post.php#L765-L774
  • https://github.com/t-hamano/wordpress-develop/blob/33a612053d5db243ac928a99ccec41d6e2f8a80e/src/wp-includes/class-wp-customize-nav-menus.php#L978-L984
  • https://github.com/t-hamano/wordpress-develop/blob/33a612053d5db243ac928a99ccec41d6e2f8a80e/src/wp-includes/theme.php#L2139-L2157
  • https://github.com/t-hamano/wordpress-develop/blob/33a612053d5db243ac928a99ccec41d6e2f8a80e/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L762-L775

t-hamano avatar May 20 '25 06:05 t-hamano

@t-hamano thanks for the reply. I believe this happens when the API endpoint is called right after the theme is switched, and only occasionally. I believe it happens on hot paths.

BogdanUngureanu avatar May 20 '25 09:05 BogdanUngureanu

I'm not an expert in this area, but do you have any ideas to fix this? Additionally, this code is also in core, so maybe submitting a core ticket may be a good idea.

t-hamano avatar May 20 '25 09:05 t-hamano

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

github-actions[bot] avatar Jun 05 '25 00:06 github-actions[bot]

Please create a core ticket for this. This is not the right place for this issue.

youknowriad avatar Nov 14 '25 23:11 youknowriad