Conversation
|
@aduth you can amend to the existing wp_add_inline_script( 'wp-api', sprintf(
'wpApiSettings.cacheSchema = true; wpApiSettings.schema = %s;',
wp_json_encode( $schema_response->get_data() )
) ); |
|
@westonruter Thanks, that works, updated in aa093eb. Not so nice to inject hand-written property setting like that, but feels a bit less error-prone overall. |
Seems the lack of network request could be attributed to session storage of the schema, not that it was picking up the schema from the API settings 😞 Certainly seems like an improvement which could be made to the client. |
aa093eb to
9cd6d77
Compare
|
Actually, it does detect the schema. The issue was ordering: The default of One worry is whether |
|
Seems like a reasonable solution for now, but this call is much slower than expected and we should seek to get rid of it as soon as possible. See https://core.trac.wordpress.org/ticket/40988 for reference. |
Supersedes #1498
Fixes #1298
This pull request seeks to bootstrap the REST API schema to prevent an unusable editor screen from being shown while the schema is fetched from the REST API.
Implementation notes:
Ideally one could hook into and append data to the default set (
schema,cacheSchema), but to my knowledge the script loader provides no such opportunities.https://github.com/WordPress/WordPress/blob/89fa297/wp-includes/script-loader.php#L510-L514
https://github.com/WordPress/WordPress/blob/89fa297/wp-includes/class.wp-scripts.php#L403-L440
It may be the case that we want to revise the above core logic to be filterable, or inject the schema by default.
Testing instructions:
Verify in your browser's Developer Tools Network tab that no request is issued for the
/wp/v2root API route when navigating to the Gutenberg editor.