[wp-trac] [WordPress Trac] #55151: View scripts of blocks are loaded in editor

WordPress Trac noreply at wordpress.org
Fri Feb 11 20:13:26 UTC 2022

#55151: View scripts of blocks are loaded in editor
 Reporter:  ocean90                  |      Owner:  (none)
     Type:  defect (bug)             |     Status:  new
 Priority:  normal                   |  Milestone:  5.9.1
Component:  Editor                   |    Version:  5.9
 Severity:  normal                   |   Keywords:
  Focuses:  javascript, performance  |
 Since WordPress 5.9 you can set a [https://developer.wordpress.org/block-
 editor/reference-guides/block-api/block-metadata/#view-script view script
 for a block] which is supposed to be only loaded on the front end.
 Unfortunately it's currently also loaded in the editor which can cause
 unexpected behaviour and also performance issues depending on the size of
 the script.

 As already documented on a
 related GitHub issue in the Gutenberg repo], the reason for this behaviour
 is caused by the preloading of some REST API routes via
 `block_editor_rest_api_preload()`. This also includes the posts endpoint
 and thus the rendered content as returned by `WP_Block:render()` which
 ultimately enqueues the script. Since the preload doesn't happen in an
 encapsulated process it can pollute any global state like the one for
 scripts and styles.

 I'm proposing to backup and restore the globals like we already do for the
 editor.php?marks=469-474,495,496#L469 global post object].

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

More information about the wp-trac mailing list