Gutenberg: FR: Async fetching prior to block registration

Created on 22 Nov 2018  路  2Comments  路  Source: WordPress/gutenberg

Is your feature request related to a problem? Please describe.
While working on Jetpack Gutenberg blocks and plugins, we've recently found a few instances where some sort of async fetching of resources prior to block registration would come in handy. Examples include:

  1. Translation files. This is relevant when Gutenberg is used outside of wp-admin, e.g. in Calypso. We have a Calypso-specific workaround (https://github.com/Automattic/wp-calypso/pull/28304) that takes care of loading translation files prior to loading Gutenberg, but we were wondering if more native tooling might be in order here. (We can't simply load translations after the editor and rely on React re-rendering strings afterwards for things like block names and descriptions that we pass to registerBlockType).
  2. Information relevant for block availability. We might want to register blocks conditionally, depending on criteria obtained from a REST API endpoint.

Describe the solution you'd like
A bit fuzzy, but maybe allow registerBlockType() (and registerPlugin()) to return a promise, and wait for that to be resolved?

Describe alternatives you've considered
For 1. -- see the workaround mentioned there.
For 2. -- In wp-admin, we're using wp_localize_script to set a global variable to contain relevant information
(None of which are particularly nice.)

/cc @sirreal @tyxla @simison @lezama @enejb

[Feature] Block API [Feature] Extensibility

Most helpful comment

@ockham, I moved your comment to https://github.com/WordPress/gutenberg/issues/2768#issuecomment-441223532. Let's discuss there, thanks.

All 2 comments

This is related to what I proposed to #2768. It all also heavily depends on #4116 which proposes to introduce a way to make blocks discoverable using some sort of API, which would allow to show them in the inserter but defer loading until you really need them.

@ockham, I moved your comment to https://github.com/WordPress/gutenberg/issues/2768#issuecomment-441223532. Let's discuss there, thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mhenrylucero picture mhenrylucero  路  3Comments

youknowriad picture youknowriad  路  3Comments

franz-josef-kaiser picture franz-josef-kaiser  路  3Comments

maddisondesigns picture maddisondesigns  路  3Comments

pfefferle picture pfefferle  路  3Comments