Skip to content

FR: Async fetching prior to block registration #12232

@ockham

Description

@ockham

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 (Gutenberg: Load Jetpack block translations in Calypso synchronously Automattic/wp-calypso#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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block APIAPI that allows to express the block paradigm.[Feature] ExtensibilityThe ability to extend blocks or the editing experience[Status] DuplicateUsed to indicate that a current issue matches an existing one and can be closed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions