Full Site Editing: Simplify how FSE blocks fetch posts #32727
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.
Changes proposed in this Pull Request
In #32529, the FSE blocks fetching posts logic was based upon an
apiFetch
fired from a custom madefetchPost
async function.While not wrong per se, it forced an API call regardless of the presence of such post in state, and on top of that, didn't take advantage of the Redux/
withSelect
perks.fetchPost
utility, now unnecessary.select( 'core' ).getEntityRecord( 'postType', postType, postId )
instead of the more convoluted custom mix ofgetEntityRecord
andapiFetch
proposed infetchPost
.withState
andwithSelect
to request a new post (viagetEntityRecord
) only when a post has been selected and its ID and type have been stored as attribute, or into state (in the Content block, that doesn't persist it).Testing instructions
wp_template
posts #32717).Fixes Dennis' concerns in #32529 (review) (well, at least tries to 😄)