Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Reduce number of dependencies for the product categories list block #771

Merged
merged 14 commits into from
Jul 29, 2019

Conversation

mikejolley
Copy link
Member

This PR improves how JS powered blocks work on the frontend, reducing the overall number of dependencies. In testing, this reduced downloaded JS from 4.8MB to 2.2MB.

Fixes #762

The changes to the webpack config are to prevent wp.element and lodash being enqueued on the frontend - we can use React only here.

How to test the changes in this Pull Request:

  1. before checking out this branch, create some product category list blocks in a page
  2. checkout and build
  3. confirm build/frontend.deps.js only contains ["react","react-dom","wp-i18n","wp-polyfill"]
  4. check existing list blocks work in the editor and on the frontend
  5. create a new product category list block - ensure it works as expected

Changelog

Reduced the number of JavaScript assets needed for the Product Category List block to improve performance.

@mikejolley mikejolley added status: needs review type: refactor The issue/PR is related to refactoring. labels Jul 26, 2019
@mikejolley mikejolley added this to the 2.3 milestone Jul 26, 2019
@mikejolley mikejolley requested a review from Aljullu July 26, 2019 15:12
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @mikejolley, that was a big refactor and it results in much lower file sizes, good job! 👏

I added some comments below, but overall looking good. 👍

assets/js/blocks/product-categories/hierarchy.js Outdated Show resolved Hide resolved
webpack.config.js Show resolved Hide resolved
webpack.config.js Outdated Show resolved Hide resolved
assets/js/blocks/product-categories/block.js Outdated Show resolved Hide resolved
@mikejolley
Copy link
Member Author

Ready for another look @Aljullu. I handled the CSS change too (wasn't difficult) and cleaned up the ID generation using a HOC. Let me know your thoughts and if you think it's good for 2.3.

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes @mikejolley! Everything is working fine and code looks good. I just added one minor comment but once it's addressed this is ready to go.

};

export default withInstanceId( ProductCategoriesBlock );
export default withComponentID( ProductCategoriesBlock );
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that's very nitpicky, but what do you think about renaming withComponentID and componentID to withComponentId and componentId (notice the camel case)? This way it's consistent with withInstanceIdand instanceId.

This also seems to be the consensus they arrived in Gutenberg: WordPress/gutenberg#6741.

@mikejolley mikejolley added the release: cherry-pick Cherry picked into the relevant release branch. label Jul 29, 2019
@mikejolley mikejolley merged commit 254d7ad into master Jul 29, 2019
@mikejolley mikejolley removed the release: cherry-pick Cherry picked into the relevant release branch. label Jul 29, 2019
@ralucaStan ralucaStan deleted the update/product-category-block-dependencies branch March 2, 2021 14:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: refactor The issue/PR is related to refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JavaScript errors when using a plugin that minifies JS files
3 participants