[wp-trac] [WordPress Trac] #60485: Editor: Add missing support for script handles in asset files for blocks

WordPress Trac noreply at wordpress.org
Fri Feb 9 11:29:06 UTC 2024


#60485: Editor: Add missing support for script handles in asset files for blocks
-------------------------+--------------------
 Reporter:  gziolo       |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  6.5
Component:  Editor       |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+--------------------
 In the [documentation for `WPDefinedAsset`
 definition](https://developer.wordpress.org/block-editor/reference-guides
 /block-api/block-metadata/#wpdefinedasset) for block metadata there is a
 note about `handle`:

 > `handle` (`string`) – the name of the script. If omitted, it will be
 auto-generated.

 We never implemented it, but it would be very useful for block authors.
 One of the limitations of the way scripts get registered for blocks is
 that whenever a single file needs to be shared between blocks, then it has
 to be registered using `wp_register_script` separately, and the script
 handle used needs to be passed to one of the script fields in
 `block.json`: `editorScript`, `script` or `viewScript`. It would be great
 if we could pass the predictable script handle in the `.asset.php` file so
 you could still use local paths in `block.json` and the rest would get
 automatically handled by WordPress core. In effect, the logic proposed
 would read the script handle from the asset file and ensure that all other
 occurrences reuse the script that is already registered under the same
 name. It would open the possibility to have firs-class support for shared
 chunks or runtimes generated by bundlers like webpack.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60485>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list