New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude reusable blocks from the global block count #11787

Merged
merged 1 commit into from Nov 19, 2018

Conversation

Projects
None yet
5 participants
@noisysocks
Member

noisysocks commented Nov 13, 2018

Fixes #11744.

Modifies getGlobalBlockCount() to exclude reusable blocks from its count. This fixes the block count including reusable blocks that have been parsed and stored into blocks.byClientId but not inserted into the post or page.

How to test

  1. Create a new post
  2. Insert a block
  3. Convert it to a reusable block
  4. Click Content Structure
  5. It should report that there is 1 block
@jorgefilipecosta

Hi @noisysocks, this seems an improvement and addresses some problems.
But we need to take into consideration the descendants of the child blocks.
If we convert a columns block with two columns and with one paragraph inside each column to a reusable block, the columns block is not counted but the 2 "column" blocks and 2 paragraph blocks are counted so we have an additional four blocks in the global block count.
We are also taking into account all paragraphs and headings inside reusable blocks in the global headings and paragraphs counts.

@mtias

This comment has been minimized.

Contributor

mtias commented Nov 13, 2018

We are also taking into account all paragraphs and headings inside reusable blocks in the global headings and paragraphs counts.

I'd consider this a nice to have and not high priority. The most important is to fix the surplus in the counts.

@noisysocks noisysocks force-pushed the fix/global-block-count-includes-reusable-blocks branch from 488bb0d to 30bcbdb Nov 14, 2018

@noisysocks

This comment has been minimized.

Member

noisysocks commented Nov 14, 2018

Thanks Jorge! Good catch. I've modified the selector to use getClientIdsWithDescendants which does exactly what we need here.

@noisysocks noisysocks force-pushed the fix/global-block-count-includes-reusable-blocks branch from 30bcbdb to a248a9d Nov 14, 2018

Exclude reusable blocks from the global block count
Modifies getGlobalBlockCount() to exclude reusable blocks from its
count. This fixes the block count including reusable blocks that have
been fetched and parsed but not inserted into the post or page.

@noisysocks noisysocks force-pushed the fix/global-block-count-includes-reusable-blocks branch from a248a9d to 7e70858 Nov 14, 2018

@youknowriad youknowriad modified the milestones: 4.4, 4.5 Nov 15, 2018

},
( state ) => [
state.editor.present.blocks.order,
state.editor.present.blocks.byClientId,

This comment has been minimized.

@youknowriad

youknowriad Nov 15, 2018

Contributor

Is it really worth memoizing selectors if they depend on these two elements particularly? I feel state.editor.present.blocks.byClientId changes so often that it's just a waste of time to memoize these selectors.

This comment has been minimized.

@youknowriad

youknowriad Nov 15, 2018

Contributor

Thoughts on this @aduth?

This comment has been minimized.

@noisysocks

noisysocks Nov 16, 2018

Member

But it seems wasteful to have this selector run when something unrelated e.g. a post attribute is modified, no?

This comment has been minimized.

@youknowriad

youknowriad Nov 16, 2018

Contributor

I don't know honestly, it feels like typing in blocks is the most impactful thing in terms of performance, changing an attribute only get triggered once and not extensively.

Anyway, just something to keep in mind for now, there's no clear "winner"

@youknowriad

LGTM 👍

@youknowriad youknowriad merged commit c7caf4f into master Nov 19, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@youknowriad youknowriad deleted the fix/global-block-count-includes-reusable-blocks branch Nov 19, 2018

grey-rsi pushed a commit to OnTheGoSystems/gutenberg that referenced this pull request Nov 22, 2018

Exclude reusable blocks from the global block count (WordPress#11787)
Modifies getGlobalBlockCount() to exclude reusable blocks from its
count. This fixes the block count including reusable blocks that have
been fetched and parsed but not inserted into the post or page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment