Skip to content
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

Improve Homepage Posts block editor performance #499

Merged
merged 14 commits into from
Jun 18, 2020

Conversation

adekbadek
Copy link
Member

@adekbadek adekbadek commented May 28, 2020

All Submissions:

Changes proposed in this Pull Request:

Improve the performance of Homepage Blocks post in the editor.

Closes #493

How to test the changes in this Pull Request:

  1. Create a page with n of Homepage Posts blocks, each with a category assigned
  2. On master, load the page in the editor. Observe a larger* than n number of requests to /v2/posts WP API endpoint**
  3. Switch to this branch and rebuild
  4. Observe that the number of /v2/posts requests on editor page load matches the number of blocks on the page
  5. Observe that some of the block posts query controls are disabled during the update***
  6. Simulate an error by blocking the first /v2/posts request****. Observe that the sabotaged block displays an error, but the rest are displayed as expected. Such an error on master should cause an infinite loading state on the block.

* I went with 10, which triggered 55 requests
** To see the no. of requests in Chrome's network tab:

image

*** Not all @wordpress/components control components support the disabled prop - changing that is in progress at WordPress/gutenberg#22701

**** In Chrome network tab:
image

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@laurelfulford
Copy link
Contributor

I've tested a few cases in the editor, more with an eye to see if things were working the same way as before. Adding and removing blocks works really well, whether the blocks are added/removed at the top of the page, bottom or middle.

I did run into an issue when reordering the blocks -- it looks like the posts aren't updated at all when the order is changed, though they correct themselves when doing another action that updates them (like add/delete):

reordering

I also ran into something weird when changing the number of posts per block -- for the most part, this updated pretty well, but from time to time I managed to "trick" it, and could set the number of posts per block to something that would show under Display Settings, but wouldn't be reflected in the editor. The following clip happened after changing the counts of a few of the blocks; the third block is correctly showing 2 posts from the previous change:

https://cloudup.com/cAY3FIeblcF

Let me know if I can provide any info about either of these!

@adekbadek
Copy link
Member Author

Thanks for catching those, Laurel!

  1. Update on block reordering added here: 634aba0
  2. Wrong counts issue: I could not reproduce that, could you please provide a list of steps to reproduce?

@laurelfulford
Copy link
Contributor

Thanks Adam! Block reordering looks good now in my testing 👍

Wrong counts issue: I could not reproduce that, could you please provide a list of steps to reproduce?

I could recreate a couple times by doing the following:

  1. Added 7 blocks to the editor, displaying 3 stories each.
  2. Went up and down the page, picking a block and increasing the stories in a block up to 6, or back down to three if I'd already hit it. To change the count, I would click on the number text input, and use my up/down keyboard arrows.
  3. Each time I would wait for the posts to stop loading before editing the next block.

At some point, the count gets weird -- the first time I tried to recreate today, the second block I changed was set to 6 posts, but only displayed 5. The second time it took a bit more editing; after changing 4-5 blocks, I ended up with one that says it has a count of 3, but is actually displaying 7.

My localhost can get pretty slow -- that could also be contributing, I'm not sure.

Just let me know if it'd be more helpful to do a quick screenshare or something -- issues that are hard to recreate kind of drive me nuts, you never know if they're happening in their own weird bubble (like my slow localhost), or if there's just a really specific step that is hard to hit!

@adekbadek
Copy link
Member Author

adekbadek commented Jun 4, 2020

I figured out a way to reproduce that:

  1. insert a single block, set it to 3 posts (which is the default)
  2. change it to 10, then immediately back to 3
  3. observe that the block has 10 posts (after fetch completes), but input displays 3

In pt. 2 the 3 posts request is cached, so it completes before 10 request. When 10 comes back, posts are replaced with the fetched amount.

The reason is twofold:

  1. the input is not disabled (that's fixed in Support disabled prop in ToggleControl, QueryControls WordPress/gutenberg#22701)
  2. redux-sagas debounce effect does not cancel the effect "from before", which may result in a race condition

I've solved 2. by implementing a slightly different debouncing strategy: a1e6345 and it should work as expected now, even without the disabling of the input.

@adekbadek adekbadek requested a review from laurelfulford June 9, 2020 13:24
Copy link
Contributor

@laurelfulford laurelfulford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've solved 2. by implementing a slightly different debouncing strategy: a1e6345 and it should work as expected now, even without the disabling of the input.

Can confirm! I hammered it a lot more than I did the first time -- changing the posts-per-block count on multiple posts before each had finished loading -- and each time they landed on the right number.

Thanks Adam! Marking as approved from a behaviour perspective, but it would probably be good to get the 👍 from Jeff, too, just to make sure everything looks OK code-wise.

@jeffersonrabb
Copy link
Contributor

I think we should consider removing the disabled states. From a UI perspective it's nice to show the activity, but on pages with a large number of blocks this leads to significant periods of time with locked UI. Here's a video showing this. It was taken on a Jurassic Ninja instance with approximately 300 Posts, on a Page with 27 Homepage Posts blocks. Several Newspack sites have homepages of similar or greater density.

https://cloudup.com/cTmN9CMSh9V

@adekbadek what do you think?

@adekbadek
Copy link
Member Author

Done in 1600925 . Note that just the sidebar UI controls' disabling is removed, the blocks will still be dimmed until the reflow completes.

Copy link
Contributor

@jeffersonrabb jeffersonrabb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working really well! I still need another hour or two with the store but two things that can be discussed and/or addressed:

registerBlockType( `newspack-blocks/${ name }`, settings );
registerQueryStore( `newspack-blocks/${ name }` );
registerBlockType( BLOCK_NAME, settings );
registerHomepagePostsBlockStore();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adekbadek
Copy link
Member Author

In FSE the block is registered with a different name

I think that's ok – FSE renames the block, so it doesn't matter what's the original name. And this PR does not change the name of the block – there's just some refactoring to avoid duplication.

store is initiated from a different place

Good catch, I've updated the code in d1ada72 to be backwards-compatible.

a few other differences […] changes in this branch are likely to break that implementation

Besides the settings and registerQueryStore importing I can't see any other "points of contact". FSE integration uses this repo's edit.js, but it's own version of editor.js – which register the block & store. I think the changes in this PR are now backwards-compatible.

since the blocks may take a noticeable interval to update and since the changes applied mid-update are harmless, removing the state change might remove friction from the editing process.

I agree that not disabling the inputs makes for a smoother editing experience, but "dimming" of the block content does not prevent the user from editing. I think it's good feedback that the reflow is still in progress – perhaps there could be less dimming, so that it's more subtle?

@adekbadek
Copy link
Member Author

As @jeffersonrabb pointed out, some changes have indeed broken backwards compatibility – namely internal handling the block name. Fixed in 4ee4b33

Copy link
Contributor

@jeffersonrabb jeffersonrabb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted several (probably) unnecessary disabled references.

@@ -159,6 +159,7 @@ class QueryControls extends Component {
tagExclusions,
onTagExclusionsChange,
enableSpecific,
disabled,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@@ -169,6 +170,7 @@ class QueryControls extends Component {
checked={ specificMode }
onChange={ onSpecificModeChange }
label={ __( 'Choose Specific Posts', 'newspack-blocks' ) }
disabled={ disabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@@ -183,6 +185,7 @@ class QueryControls extends Component {
'Begin typing post title, click autocomplete result to select.',
'newspack-blocks'
) }
disabled={ disabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@@ -194,6 +197,7 @@ class QueryControls extends Component {
fetchSuggestions={ this.fetchAuthorSuggestions }
fetchSavedInfo={ this.fetchSavedAuthors }
label={ __( 'Authors', 'newspack-blocks' ) }
disabled={ disabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@@ -204,6 +208,7 @@ class QueryControls extends Component {
fetchSuggestions={ this.fetchCategorySuggestions }
fetchSavedInfo={ this.fetchSavedCategories }
label={ __( 'Categories', 'newspack-blocks' ) }
disabled={ disabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@@ -214,6 +219,7 @@ class QueryControls extends Component {
fetchSuggestions={ this.fetchTagSuggestions }
fetchSavedInfo={ this.fetchSavedTags }
label={ __( 'Tags', 'newspack-blocks' ) }
disabled={ disabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@@ -236,6 +242,7 @@ class QueryControls extends Component {
fetchSuggestions={ this.fetchTagSuggestions }
fetchSavedInfo={ this.fetchSavedTags }
label={ __( 'Excluded Tags', 'newspack-blocks' ) }
disabled={ disabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@@ -161,7 +161,7 @@ class AutocompleteTokenField extends Component {
* Render.
*/
render() {
const { help, label = '' } = this.props;
const { help, label = '', disabled } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@@ -172,6 +172,7 @@ class AutocompleteTokenField extends Component {
onChange={ tokens => this.handleOnChange( tokens ) }
onInputChange={ input => this.debouncedUpdateSuggestions( input ) }
label={ label }
disabled={ disabled }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3580fa7

@adekbadek adekbadek requested a review from jeffersonrabb June 17, 2020 09:08
Copy link
Contributor

@jeffersonrabb jeffersonrabb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're good to go on this!

@adekbadek adekbadek merged commit e1c68c5 into master Jun 18, 2020
@adekbadek adekbadek deleted the fix/homepage-posts-perf branch June 18, 2020 10:45
matticbot pushed a commit that referenced this pull request Jun 18, 2020
# [1.8.0](v1.7.2...v1.8.0) (2020-06-18)

### Bug Fixes

* correct count ([19c7a6c](19c7a6c))
* donations wizard link ([84e0092](84e0092))

### Features

* improve Homepage Posts block editor performance ([#499](#499)) ([e1c68c5](e1c68c5)), closes [#493](#493)
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.8.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@adekbadek adekbadek mentioned this pull request Apr 23, 2021
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Homepage Posts block editor performance
4 participants