Framework: Preload common API data #2501
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related: #1974
This pull request seeks to introduce a mechanism for bootstrapping common REST API requirements for use in with the
withAPIData
higher-order component (#1974). Specifically, this improves perceived performance by making endpoint data available immediately upon page load, avoiding components flashing in and out (e.g. LastRevision in ##1974, PostFormats in #2500) where the API data would otherwise load asynchronously.Implementation notes:
While not entirely necessary for the changes here, I split the response between
body
andheaders
. This will be useful for future enhancements to thewithAPIData
higher-order component in allowing a "has more results?" type functionality.Testing instructions:
Repeat testing instructions from #1974, noting that the LastRevision component appears immediately upon page load if revisions are available for a post. Ensure that there is no network request occurring to retrieve
/wp/v2/posts/%d/revisions
.