Gutenberg: Blocks: Deleting a new paragraph block triggers a tags request

Created on 11 Jun 2018  路  9Comments  路  Source: WordPress/gutenberg

Describe the bug

When deleting a new paragraph block, a network request is unexpectedly issued for the /wp/v2/tags endpoint. This request is cancelled immediately if the block is deleted by backspace, but not if by the side menu Trash button.

To my knowledge, I can't think of a reason we would need to request tags at this point.

To Reproduce

  1. Navigate to Posts > Add New
  2. _Ensure the Tags sidebar is visible and expanded_
  3. Click the writing prompt
  4. Press backspace

Expected behavior

The block is deleted. No need for network request.

Actual behavior

The block is deleted, but a request is issued for the /wp/v2/tags endpoint (made obvious in observing the browser developer tools Network tab).

Desktop (please complete the following information):

  • OS: macOS 10.13.4
  • Browser: Chrome Version 67.0.3396.79
REST API Interaction [Feature] Blocks [Status] Blocked [Type] Bug

Most helpful comment

This is fun. Software is cool.

All 9 comments

Clarification: This only occurs when the "Tags" sidebar is visible and expanded.

This is fun. Software is cool.

Just realized that I created #8024 as a duplicate of this one.

@jorgefilipecosta had some useful (and I believe correct) context there:

If we close and reopen the sidebar or go from the block sidebar to the document sidebar, the taxonomies are requested again.
What happens is that HierarchicalTermSelector and FlatTermSelector request the taxonomies on Mount.
I think what happens here is that when removing a block we go from block sidebar to document sidebar so the taxonomy component are mounted and the request happen.

Each time we select and unselect a block the taxonomies are requested again, what's happening here is the wrong behavior of requesting taxonomies on mount in this cases.

If we merge #5826 and expend the usage of our data module to all taxonomies this problem is going to get fixed.

Sounds like this could be a matter of changing the term selectors to use the entities selectors, i.e. select( 'core' ).getEntityRecords( 'taxonomy', 'post_tag', { post_per_page: -1 } )

Related #10274

So it looks like this has evolved a bit, possibly due to #10642 and likely other changes as the UI has evolved a bit since then.

Testing steps:

  1. New Post
  2. Tags panel open
  3. Click into empty block
  4. Press delete

No tags

It doesn't send any requests when there are no tags assigned. I think this likely covers the majority of situations where this would occur.
no-tags-requests

Tags

It sends 2 identical back-to-back requests if there are any tags assigned:
tags-requests

Notes

  • You can no longer actually delete the only block on the page, but pressing Backspace still sends the requests.
  • If you are using the unified toolbar at the top, using the Remove Block menu item does not trigger the requests.
  • It does not send any requests when blocks after the first block are deleted. This only happens for the first block.
  • If there are multiple blocks on the page, and the first block is deleted, a single tags request is sent.

Sounds like this could be a matter of changing the term selectors to use the entities selectors, i.e. select( 'core' ).getEntityRecords( 'taxonomy', 'post_tag', { post_per_page: -1 } )

This approach is blocked by #11643. Moving to Future: 5.1

Sounds like this could be a matter of changing the term selectors to use the entities selectors, i.e. select( 'core' ).getEntityRecords( 'taxonomy', 'post_tag', { post_per_page: -1 } )

This approach is blocked by #11643. Moving to Future: 5.1

Related: #13849

Looks like I can't reproduce this anymore.

Was this page helpful?
0 / 5 - 0 ratings