web-stories-wp icon indicating copy to clipboard operation
web-stories-wp copied to clipboard

Masks: Improve bundle size

Open swissspidy opened this issue 2 years ago • 1 comments

Feature Description

The constants.js file in the masks package is a whopping 300KB large. This also shows in bundle analyzer:

Screenshot 2022-07-20 at 17 43 18

That makes sense, because it contains a ton of clip paths.

I think the way the masks package is structured can be improved though to make this more efficient.

For example, in most places we only use functions like canSupportMultiBorder, generateMaskId or simple constants like MaskTypes

The full list of clip paths is only used in the shapes pane in the library:

https://github.com/GoogleForCreators/web-stories-wp/blob/22cf54d030e407f469350f21273f6d1c223aa99b/packages/story-editor/src/components/library/panes/shapes/shapesPane.js#L24

We should be able to improve performance here by reducing the bundle size using the following to steps:

  1. Create a separate export in the masks package just for the clip paths
  2. Dynamically import that separate definition in the shapes pane

Alternatives Considered

Additional Context

swissspidy avatar Jul 20 '22 16:07 swissspidy

We should be able to improve performance here by reducing the bundle size using the following to steps:

  1. Create a separate export in the masks package just for the clip paths
  2. Dynamically import that separate definition in the shapes pane

That's easier said than done, because utils like getMaskByType() and getElementMask obviously rely on MASKS as well.

swissspidy avatar Sep 19 '22 15:09 swissspidy