Make WordPress Core

Opened 6 months ago

Closed 6 months ago

Last modified 5 months ago

#60233 closed enhancement (fixed)

Editor: Support module metadata in block.json

Reported by: jonsurrell's profile jonsurrell Owned by: gziolo's profile gziolo
Milestone: 6.5 Priority: normal
Severity: normal Version: 6.5
Component: Editor Keywords: has-patch has-unit-tests has-dev-note
Focuses: Cc:

Description

Problem:

Scripts and styles can be registered for blocks via block.json metadata. There is now a Modules API, but no way to register or associate module assets with blocks via block.json metadata or the register_block_type_from_metadata function.

Proposed solution:

Introduce module fields analogous to the script fields currently supported in block.json.

The end goal would be to support editorModule, module, and viewModule. An initial version could support only viewModule given that most functionality provided by WordPress for working with the editor is only available as scripts and not accessible to modules at this time.

Background:

See https://github.com/WordPress/gutenberg/issues/57492 for prior discussion in Gutenberg.

Change History (25)

This ticket was mentioned in PR #5860 on WordPress/wordpress-develop by @jonsurrell.


6 months ago
#2

  • Keywords has-patch added

Add handling for viewModule block.json metadata when registering blocks.

Trac ticket: https://core.trac.wordpress.org/ticket/60233

@jonsurrell commented on PR #5860:


6 months ago
#3

We'll want to wait until naming questions are settled:

https://github.com/WordPress/wordpress-develop/pull/5869

@youknowriad commented on PR #5860:


6 months ago
#4

Is the naming settled, what's blocking here?

@gziolo commented on PR #5860:


6 months ago
#5

Is the naming settled, what's blocking here?

It needs a rebase after https://github.com/WordPress/wordpress-develop/pull/5869 lands. The name of the helper functions for modules follows the following pattern: wp_register_script_module, so that probably should get reflected in block.json and other places, viewScriptModule? It's a bit unfortunate that we can't extend viewScript in a backward-compatible way to support both ES Modules and legacy scripts.

@jonsurrell commented on PR #5860:


6 months ago
#6

https://github.com/WordPress/wordpress-develop/pull/5869 landed recently so I'll finish this and get it ready for review.

@jonsurrell commented on PR #5860:


6 months ago
#7

The Modules API ended up with names like "script_module." To better align, this has been updated to use viewScriptModule instead of viewModule.

@jonsurrell commented on PR #5860:


6 months ago
#8

@luisherranz @gziolo @youknowriad This is ready for review.

@jonsurrell commented on PR #5860:


6 months ago
#9

There was 1 test failure on a single PHP version that seems to be a flakey test.

@jonsurrell commented on PR #5860:


6 months ago
#10

Adding support to the @wordpress/scripts for building blocks with viewScriptModule: https://github.com/WordPress/gutenberg/pull/58203

@jonsurrell commented on PR #5860:


6 months ago
#11

Tests were failing because the number of REST fields returned in the response has changed again. They should be fixed now.

@jonsurrell commented on PR #5860:


6 months ago
#14

I've pushed changes so the asset file is not longer required to align with hhttps://github.com/WordPress/wordpress-develop/pull/5799.

@jonsurrell commented on PR #5860:


6 months ago
#16

I spotted an issue in the updated documentation

Thanks, I'll create a PR for that 👍

@gziolo commented on PR #5860:


6 months ago
#17

There is a merge conflict to resolve but otherwise we will be good to go 👍🏻

@jonsurrell commented on PR #5860:


6 months ago
#18

I've finished rebasing (it was a bit tricky) and tweaking some documentation, I this this is ready now.

#19 @gziolo
6 months ago

  • Owner set to gziolo
  • Resolution set to fixed
  • Status changed from new to closed

In 57565:

Editor: Add viewScriptModule handling to block.json metadata

Syncing changes from the Gutenberg plugin: https://github.com/WordPress/gutenberg/pull/57437.

Scripts and styles can be registered for blocks via block.json metadata. There is now a Modules API, but was no way to register or associate module assets with blocks via block.json.

Fixes #60233.
Props jonsurrell, gziolo, cbravobernal, luisherranz, youknowriad.

#20 @gziolo
6 months ago

  • Component changed from General to Editor
  • Keywords has-unit-tests needs-dev-note added
  • Milestone changed from Awaiting Review to 6.5
  • Version set to trunk

#22 @gziolo
6 months ago

  • Summary changed from Support module metadata in block.json to Editor: Support module metadata in block.json

#23 @gziolo
5 months ago

In 57677:

Editor: Add fallback for block version when registering block script module

It aligns implementation with how regular scripts are handled.

Follow-up [57437].
See #60233.

#24 @desrosj
5 months ago

In 57771:

Coding standards: Apply some changes after composer format.

Follow up to [57565], [57627], [57755],

See #60233, #60506, #60524.

Note: See TracTickets for help on using tickets.