Skip to content

[6.x]: jQuery is included after dependent asset resources when using yii2-adapter #19382

Description

@vnali

What happened?

Description

When a plugin uses yii2-adapter and an asset bundle declares JqueryAsset as a dependency, the dependent asset resources are included before jQuery.
This causes errors such as:
Uncaught ReferenceError: $ is not defined

For example, the asset bundle has:

public $depends = [
    \craft\web\JqueryAsset::class,
];

Steps to reproduce

  1. register an asset bundle in widget body like
    public function init()
    {
        $this->sourcePath = "@vnali/counter/resources";

        $this->depends = [
            JqueryAsset::class,
        ];

        $this->js = [
            'js/counter-widget-settings.js',
        ];

2- counter-widget-settings.js is loaded before vendor/craft/legacy/jquery/dist/jquery.js?v=6.0.0-alpha.16)
3- it throws an Uncaught ReferenceError: $ is not defined

Expected behavior

I would expect the generated resources to be ordered as:
jquery.js
counter-widget-settings.js

Actual behavior

However, they are currently included as:

counter-widget-settings.js
jquery.js

Craft CMS version

6.0.0-alpha.16

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

  • craft-counter

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions