Skip to content
This repository has been archived by the owner on Oct 10, 2022. It is now read-only.

Missing @wordpress/server-side-render dependency #292

Open
khromov opened this issue Nov 28, 2020 · 3 comments
Open

Missing @wordpress/server-side-render dependency #292

khromov opened this issue Nov 28, 2020 · 3 comments

Comments

@khromov
Copy link

khromov commented Nov 28, 2020

Feature Request

Is your feature request related to a problem? Please describe.
It appears that the @wordpress/server-side-render dependency is not included by default in CGB, which makes it impossible to import the ServerSideRender component.

Describe the solution you'd like
It would be good if all packages that are published for the block editor would be included in Gutenberg. See full list: https://developer.wordpress.org/block-editor/packages/

Describe alternatives you've considered
You can import it manually using npm i @wordpress/server-side-render dependency.

Teachability, Documentation, Adoption, Migration Strategy
N/A

@gollenia
Copy link

gollenia commented Jan 9, 2021

What I discovered was, that the final package coming out from CGB Scripts is way smaller (ca. 50k) than the WP-CLI script (about 150k). I guess it comes from NOT importing all packages. ServerSideRenderer is a not recommended and not oftenly used package (I use it, though), so I guess tha's the reason why they droped it. As you wrote, you can opt it in with npm i @wordpress/server-side-render

@khromov
Copy link
Author

khromov commented Jan 10, 2021

@gollenia I don't think you are supposed to actually install the @wordpress/server-side-render package for your custom blocks. It's already included in Gutenberg!

You might get a different incompatible version than Gutenberg is actually running and it bloats your bundle size.

Instead what should happen is that the bundler should resolve the dependency to the global wp object.

When using the official @wordpress/scripts build environment instead of CGB and running import ServerSideRender from '@wordpress/server-side-render'; it actually gets transpiled down to the following in the finished build:

/***/ "@wordpress/server-side-render":
/*!***************************************************!*\
  !*** external {"this":["wp","serverSideRender"]} ***!
  \***************************************************/
/***/ (function(module, exports) {

(function() { module.exports = this["wp"]["serverSideRender"]; }());

/***/ }),

Can't get any smaller than that! 😄

CGB also does this for some classes correctly, but not for @wordpress/server-side-render which is what this issue is about.

@gollenia
Copy link

gollenia commented Jan 10, 2021

OK, I get the point. So I did it all wrong, since I also manually imported api-fetch and compose, both packages seemed to be missing.
However, on the official Wordpress Developer page I just found that both cgb-scripts AND wp-cli are deprecated

https://developer.wordpress.org/block-editor/tutorials/block-tutorial/generate-blocks-with-wp-cli/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants