#58208 closed defect (bug) (fixed)
`wp_enqueue_registered_block_scripts_and_styles` is called twice
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.3 | Priority: | normal |
| Severity: | normal | Version: | 5.0 |
| Component: | Editor | Keywords: | has-patch |
| Focuses: | Cc: |
Description
This is a follow-up to #45065.
That ticket introduced the wp_enqueue_registered_block_scripts_and_styles function and set it as a callback for both the enqueue_block_editor_assets and enqueue_block_assets actions.
There are two actions to enqueue block assets: enqueue_block_editor_assets and enqueue_block_assets. The former enqueues the assets to the editor and the later enqueues them to the front-and and the editor.
Given wp_enqueue_registered_block_scripts_and_styles is already bound to the enqueue_block_assets (front-end & editor), it is unnecessary to bind it to enqueue_block_editor_assets (editor) as well.
Change History (9)
This ticket was mentioned in PR #4356 on WordPress/wordpress-develop by @oandregal.
3 years ago
#1
- Keywords has-patch added
@oandregal commented on PR #4356:
3 years ago
#3
Committed at https://core.trac.wordpress.org/changeset/55695
This ticket was mentioned in PR #4498 on WordPress/wordpress-develop by @oandregal.
3 years ago
#4
Trac ticket https://core.trac.wordpress.org/ticket/58208
Reverts changeset https://core.trac.wordpress.org/changeset/55695
## What
This PR reverts PR https://github.com/WordPress/wordpress-develop/pull/4356
## Why
It caused issues in the ordering of styles in the editor, which went unnoticed in the testing. The reason is that block styles (editor-only and front styles) would now be enqueued using the enqueue_block_assets which runs later than the enqueue_block_editor_assets hook.
The order of styles enqueued before the change was:
- front styles registered for blocks, via
styleshandle (block.json) - editor styles registered for blocks, via
editorStyleshandle (block.json) - editor styles enqueued via
enqueue_block_editor_assetshook - front styles enqueued via
enqueue_block_assetshook
The order of styles enqueued after the change was:
- editor styles enqueued via
enqueue_block_editor_assetshook - front styles registered for blocks, via
styleshandle (block.json) - editor styles registered for blocks, via
editorStyleshandle (block.json) - front styles enqueued via
enqueue_block_assetshook
## How to test
- Use this PR.
- Install and activate the test plugin iframed-inline-styles.zip.
- Go to the editor and add the block "iframed-inline-styles".
- The expected result is that padding is 20px and border width is 2px:
@oandregal commented on PR #4498:
3 years ago
#6
I considered an alternative: enqueue the block styles for the editor using the enqueue_block_editor_assets and the block styles for the front using the enqueue_block_assets. This would result in the block styles being loaded before the corresponding styles of the hook:
- editor styles registered for blocks, via
editorStyleshandle (block.json) - editor styles enqueued via
enqueue_block_editor_assetshook - front styles registered for blocks, via
styleshandle (block.json) - front styles enqueued via
enqueue_block_assetshook
This may seem the correct behavior. However, the enqueue_block_editor_assets hook has been used by themes to override block styles for the editor (see hook in use and styles for TwentyTwenty, for example). Using this approach the styles of the theme would load 2nd, having to use greater specificity to override the front styles of the blocks that load 3rd.
@oandregal commented on PR #4356:
3 years ago
#7
@oandregal commented on PR #4498:
3 years ago
#9
Committed at https://core.trac.wordpress.org/changeset/55852
Trac ticket https://core.trac.wordpress.org/ticket/58208
Follow-up to https://core.trac.wordpress.org/ticket/45065
## What
This PR removes the
wp_enqueue_registered_block_scripts_and_stylescallback from theenqueue_block_editor_assetsaction.## Why
There are two actions to enqueue block assets:
enqueue_block_editor_assetsandenqueue_block_assets. The former enqueues the assets to the editor and the later enqueues them to the front-and AND the editor.Given
wp_enqueue_registered_block_scripts_and_stylesis already bound to theenqueue_block_assets(front-end & editor), it is unnecessary to bind it toenqueue_block_editor_assets(editor) as well.This was originally introduced at https://github.com/WordPress/wordpress-develop/commit/76525a75b7e84a8a34aede1b8aef4aecb6623bf8 and hasn't been modified since.
## How
Removes the action callback from being hooked to
enqueue_block_editor_assets.## How to test
## SVN commit message
{{{txt
Enqueue registered assets once.
This PR removes the
wp_enqueue_registered_block_scripts_and_stylescallback from theenqueue_block_editor_assetsaction.There are two actions to enqueue block assets:
enqueue_block_editor_assetsandenqueue_block_assets. The former enqueues the assets to the editor and the later enqueues them to the front-and and the editor. Givenwp_enqueue_registered_block_scripts_and_stylesis already bound to theenqueue_block_assets(front-end & editor), it is unnecessary to bind it toenqueue_block_editor_assets(editor) as well.This was originally introduced at [44157] and hasn't been modified since.
Props ?
Fixes #45065.
}}}