Repository navigation
Defer the editor script through the supported strategy arg - #190
Merged
Merged
Conversation
roborourke
requested changes
Oct 16, 2026
roborourke
left a comment
Contributor
There was a problem hiding this comment.
If the intention was always to defer it (and note there might have been some other code in a project or elsewhere making use of this arg overload) then it'd be good to check it works with that fix and to defer through the proper WP system, rather than ignore it altogether.
A PHP test is probably overkill for this change, but it doesn't hurt :)
WordPress never recognised a 'defer' key in the $args array of wp_enqueue_script(), so the script was never deferred. Since 7.0 core also reports unknown keys with _doing_it_wrong(). Use 'strategy' => 'defer', available since WordPress 6.3.
nlemoine
force-pushed
the
fix-enqueue-defer-arg
branch
from
October 16, 2026 16:17
2cb0ab4 to
fee0b4e
Compare
Contributor
Author
|
Good point, the intention was clearly to defer it. Switched to |
roborourke
approved these changes
Oct 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
enqueue_assets_for_post()passes'defer' => truein the$argsarray ofwp_enqueue_script(). That key has never been supported, so the script was never actually deferred. Since WordPress 7.0, unknown keys also trigger a_doing_it_wrong()notice on every block editor load:This switches to
'strategy' => 'defer', available since WordPress 6.3. The script only callsregisterPlugin(), and deferred scripts run beforeDOMContentLoaded, so before the editor is initialised.Tests enqueue the editor assets and check that no incorrect usage notice is raised and that the printed script tag has the
deferattribute. The PHPUnit workflow doesn't build the JS, so the test creates a minimalbuild/index.asset.phpwhen it is missing and removes it afterwards. Both tests fail against the previous code on WP 7.1, and the deferred check fails on WP 6.9 if the key is removed.