Opened 3 years ago
Closed 3 years ago
#55151 closed defect (bug) (fixed)
View scripts of blocks are loaded in editor
Reported by: | ocean90 | Owned by: | ocean90 |
---|---|---|---|
Milestone: | 5.9.1 | Priority: | normal |
Severity: | normal | Version: | 5.9 |
Component: | Editor | Keywords: | has-patch commit fixed-major dev-feedback |
Focuses: | javascript, performance | Cc: |
Description
Since WordPress 5.9 you can set a 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 global post object.
Change History (5)
This ticket was mentioned in PR #2312 on WordPress/wordpress-develop by ocean90.
3 years ago
#1
- Keywords has-patch added
#3
@
3 years ago
- Owner set to ocean90
- Resolution set to fixed
- Status changed from new to closed
In 52733:
Related: https://github.com/WordPress/gutenberg/issues/33542
Due to the REST API preloading we may enqueue alot of assets in the editor which are only intended for the frontend. By resetting the globals for scripts/styles we can prevent this.
Trac ticket: https://core.trac.wordpress.org/ticket/55151