Opened 12 years ago
Last modified 6 years ago
#21520 new defect (bug)
Prevent recursive script dependencies in wp_enqueue_script
Reported by: | batmoo | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Script Loader | Keywords: | needs-patch |
Focuses: | Cc: |
Description
If a script sets itself as a dependency, we should catch that, strip out the dependency, and throw a _doing_it_wrong
:
wp_enqueue_script( 'my-script', '/path/to/file.js', array( 'my-script' ) );
This may need to be done at the lowest level possible, i.e. _WP_Dependency
Attachments (2)
Change History (16)
#2
@
12 years ago
Wouldn't that break WP_Dependencies and throw PHP fatal error the first time it's attempted (so the dev that tried it would know he did something wrong)?
If we go there we may need to handle circular dependencies too. Example:
add_action( 'init', 'deps_test' ); function deps_test() { wp_register_script( 'my-1', '/one.js', array('my-2'), '123', true ); wp_register_script( 'my-2', '/two.js', array('my-1'), '123', true ); wp_enqueue_script('my-1'); }
#3
@
12 years ago
- Cc info@… added
I would rather see such code break with a yelling error to force authors to catch it before they release it into the wild.
#5
follow-up:
↓ 6
@
12 years ago
So these themes I'm seeing break were passing a string instead of an array for the dependencies. Thus the dependency was ignored. With [21420] these dependencies suddenly started working. Alas, some of them were circular dependencies that no one noticed before since the string dependency was thrown out.
This is very edge, but it is fatal and rather hard to track down since the exhaustion usually happens somewhere in the depths of all_deps().
#7
@
12 years ago
I'm with toscho on this...
Seems like a user error that should be front and center. Glazing over it might cause more confusion than benefit.
#12
@
9 years ago
I've just spent ~1 hour worrying about why I'm getting segfault on every pageload, and with this simple path I have no idea why it isn't resolved yet...
Related: #20683