Gutenberg: Exposing utilities ('classnames', lodash'...) to avoid duplicating them in third party blocks

Created on 20 Jul 2018  Â·  4Comments  Â·  Source: WordPress/gutenberg

Would it be a good idea to expose some of the regularly used (and useful) packages like classnames and lodash, in - for example - wp.utils to allow third party plugins to use them?

It would save having to include them in every plugin that creates blocks, while it's already part of Gutenberg.

Edit: I just realised that lodash is already available. Is classnames also available somewhere?

[Type] Code Quality [Type] Question

Most helpful comment

Was just talking about this with @dimofte — it'd be great to see classnames available as an external, like lodash is.

All 4 comments

Was just talking about this with @dimofte — it'd be great to see classnames available as an external, like lodash is.

There's a certain amount of support commitment which comes with exposing new vendor dependencies. The jQuery 3.x migration saga is a good example of the challenges this poses over time. React and Lodash are too pivotal and too large to _not_ expose, hence their inclusion. The same cannot necessarily be said about all utilities which Gutenberg uses.

I tried to inline rememo in one of the existing modules in https://github.com/WordPress/gutenberg/pull/17863. I didn't notice huge benefits from doing it. It looks like this isn't a real issue for very small packages like classnames. See related comment from @senadir in https://github.com/WordPress/gutenberg/pull/17863#issuecomment-541577559:

createSelector does make sense since selectors are used extensively in wordpress/data, but classnames doesn't make sense since it's already 300 bytes gziped

Let’s close this issue for the time being as we decided in #17863 that promoting smaller utility methods to public APIs would introduce too much work to maintain them. At the same the benefits like decreased bundles size are way too small. Let’s reopen this issue later when there are new ways to optimize the setup we have or we find bigger libraries to extract, similar to what we did with react, lodash or moment script handles or with inlining redux.

Libraries considered in the exploration:

  • rememo
  • memize
  • classnames
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ellatrix picture ellatrix  Â·  3Comments

davidsword picture davidsword  Â·  3Comments

mhenrylucero picture mhenrylucero  Â·  3Comments

nylen picture nylen  Â·  3Comments

BE-Webdesign picture BE-Webdesign  Â·  3Comments