No Code Attached Yet bug
avatar vaidokas
vaidokas
21 Aug 2023

Steps to reproduce the issue

Module template /modules/mod_my_module/tmpl/default.php:

$wa = $app->getDocument()->getWebAssetManager();
$wr = $wa->getRegistry();

// Registering `media/mod_my_module/joomla.asset.json` file.
$wr->addExtensionRegistryFile('mod_my_module');

if ($wa->assetExists('style', 'mod_my_module.custom-style')) {
    // Module assets manifest is registered but not parsed. So, all module assets are considered as not existing.
    $wa->useStyle('mod_my_module.custom-style'); // This line will never be executed.
} else {
    // The default stylesheet is always used.
    $wa->useStyle('mod_my_module.default-style');
}

Module assets manifest /media/mod_my_module/joomla.asset.json:

{
    "$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
    "name": "mod_my_module",
    "version": "1.0.0",
    "description": "My Module",
    "assets": [
        {
            "name": "mod_my_module.default-style",
            "type": "style",
            "uri": "mod_my_module/default.css"
        },
        {
            "name": "mod_my_module.custom-style",
            "type": "style",
            "uri": "mod_my_module/custom.css"
        }
    ]
}

Expected result

Both files /media/mod_my_module/css/custom.css and /media/mod_my_module/css/default.css exist. Only
/media/mod_my_module/css/custom.css should be included into the document, because it is defined (exists) in the /media/mod_my_module/joomla.asset.json file.

Actual result

At a check-up, the module asset manifest is registered but not parsed. So, all module assets are considered as not existing. The stylesheet /media/mod_my_module/css/default.css is included into the document instead of /media/mod_my_module/css/custom.css.

Joomla Version

Joomla! 4.3.3 Stable [ Bora ] 11-July-2023 16:00 GMT

Additional comments

Neither the Joomla\CMS\WebAsset\WebAssetRegistry::addRegistryFile nor the Joomla\CMS\WebAsset\WebAssetManager::assetExists functions parse the class variable Joomla\CMS\WebAsset\WebAssetRegistry::$dataFilesNew which holds newly added assets registries. The function Joomla\CMS\WebAsset\WebAssetRegistry::parseRegistryFile is protected, so can not be called from the template of the module.

avatar vaidokas vaidokas - open - 21 Aug 2023
avatar vaidokas vaidokas - change - 21 Aug 2023
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 21 Aug 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 21 Aug 2023
avatar Fedik Fedik - change - 21 Aug 2023
Labels Added: bug
avatar Fedik Fedik - labeled - 21 Aug 2023
avatar Fedik
Fedik - comment - 21 Aug 2023

Yeap,
Parsing done on WebAssetRegistry::get and missing on WebAssetRegistry::exists

avatar Fedik Fedik - change - 22 Aug 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-08-22 13:21:48
Closed_By Fedik
avatar Fedik Fedik - close - 22 Aug 2023
avatar Fedik
Fedik - comment - 22 Aug 2023

Please test the fix #41431

Add a Comment

Login with GitHub to post a comment