Skip to content

FR: Async fetching prior to block registration #12232

Closed

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

Activity

  1. gziolo commented on Nov 23, 2018

    @gziolo
    Member

    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.

  2. added
    [Feature] Block API
    [Feature] Extensibility
    on Nov 23, 2018
  3. gziolo commented on Nov 23, 2018

    @gziolo
    Member

    @ockham, I moved your comment to #2768 (comment). Let's discuss there, thanks.

  4. added
    [Status] Duplicate
    on Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] Block API[Feature] Extensibility[Status] Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions