No Code Attached Yet
avatar jschmi102
jschmi102
24 Sep 2024

addInlineScript does not work on 5.1.4

I've developed a module, which inserts an inline script. This works fine on all of my sites but does not on one single site though this has the same joomal version as all the other systems.
There is no error shown it just does not work. Strange is for me that insertion of scripts or styleseets work fine.

I tried to debug but could not find out anything, Checked plugins but its seems that none is involved (e.g. hhtp-header is disabled).

would be great, if someone helps to find out whats going wrong.

Steps to reproduce the issue

$wa->registerAndUseScript("js_weather0", "media/mod_js_weather/js/RGraph.common.lib.js");
$wa->registerAndUseScript("js_weather1", "media/mod_js_weather/js/RGraph.line.js");
	
$script = $helper->create_inline_script();
$wa->addInlineScript($script);

Expected result

all scripts should be there

Actual result

only the script files are ok.
Inline script is missing

System information (as much as possible)

joomla 5.1.4
php 8.2.4

Additional comments

avatar jschmi102 jschmi102 - open - 24 Sep 2024
avatar joomla-cms-bot joomla-cms-bot - change - 24 Sep 2024
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 24 Sep 2024
avatar jschmi102 jschmi102 - change - 24 Sep 2024
The description was changed
avatar jschmi102 jschmi102 - edited - 24 Sep 2024
avatar brianteeman
brianteeman - comment - 24 Sep 2024

From the limited information you have provided it is impossible to debug why your extension does not work on a specific site and does work on other sites

avatar jschmi102
jschmi102 - comment - 24 Sep 2024

hi,
did a print_r on the retuncode of $wa->addInlineScript($script);
saw these first lines;

object(Joomla\CMS\WebAsset\WebAssetManager)#884 (5) {
["registry":protected]=> object(Joomla\CMS\WebAsset\WebAssetRegistry)#518 (4) { 
["dataFilesNew":protected]=> array(0) { } 
["dataFilesParsed":protected]=> array(6) { 
["media\vendor\joomla.asset.json"]=> string(30) "media\vendor\joomla.asset.json" 
["media\system\joomla.asset.json"]=> string(30) "media\system\joomla.asset.json" 
["media\legacy\joomla.asset.json"]=> string(30) "media\legacy\joomla.asset.json" 
["media\plg_system_guidedtours\joomla.asset.json"]=> string(46) "media\plg_system_guidedtours\joomla.asset.json" 
["media\plg_behaviour_compat\es5.asset.json"]=> string(41) "media\plg_behaviour_compat\es5.asset.json"

and saw these last infos::

["onWebAssetRegistryChangedAssetOverride"]=> object(Joomla\Event\ListenersPriorityQueue)#591 (1) { 
["listeners":"Joomla\Event\ListenersPriorityQueue":private]=> array(1) { [0]=> array(1) { [0]=> object(Closure)#878 (2) { 
["this"]=> *RECURSION* ["parameter"]=> array(1) { ["$event"]=> string(10) "" } } } } } 
["onWebAssetRegistryChangedAssetRemove"]=> object(Joomla\Event\ListenersPriorityQueue)#880 (1) { 
["listeners":"Joomla\Event\ListenersPriorityQueue":private]=> array(1) { [0]=> array(1) { [0]=> object(Closure)#607 (2) { 
["this"]=> *RECURSION* ["parameter"]=> array(1) { ["$event"]=> string(10) "" } } } } } } } } ["activeAssets":protected]=> array(1) { ["script"]=> array(3) { ["xx_weather0"]=> int(1) ["xx_weather1"]=> int(1) 
["inline.fdd212cdd0684aec80324a770a7a7748"]=> int(1) } } ["locked":protected]=> bool(false) 
["dependenciesIsActual":protected]=> bool(false) ["sortedAssets":protected]=> array(1) { ["script"]=> array(0) { } } } 

on my working system I get:

RECURSION* [parameter] => Array ( [$event] => ) ) ) ) ) ) ) ) [activeAssets:protected] => Array ( [script] => Array ( [js_weather0] => 1 [js_weather1] => 1 [inline.fdd212cdd0684aec80324a770a7a7748] => 1 ) ) [locked:protected] => [dependenciesIsActual:protected] => [sortedAssets:protected] => Array ( [script] => Array ( ) )

avatar ghazal
ghazal - comment - 24 Sep 2024

A small trick that can help.
First, don't forget this:

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;

Then:

$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseScript('vuejs','mystuff/vue.2.6.14.js', [], ['defer' => true], ['core']);
$wa->registerAndUseScript('myvuescriptname','mystuff/myvuescript.js', [], ['defer' => true], ['core']);
$wa->useScript('myvuescriptname');
  • myvuescriptname is ... the name of the item
  • mystuff/myvuescript.js is the location of the script
    As I work a lot with JS frameworks and dependant scripts, I had to find a solution and this one works for me.
avatar HLeithner
HLeithner - comment - 24 Sep 2024

Don't use $wa = Factory::getApplication()->getDocument()->getWebAssetManager(); if it's not really needed (for example in the view you can use $this->getDocument()....)

Also You don't need $wa->useScript(); because you use registerAndUseScript already.

avatar HLeithner
HLeithner - comment - 24 Sep 2024

@jschmi102 I tried to make your comment more readable but didn't was really successfully, can you repost with correct styling and maybe not use print_r instead use var_dump or at least pretty copy-paste please.

avatar jschmi102 jschmi102 - change - 24 Sep 2024
Status New Closed
Closed_Date 0000-00-00 00:00:00 2024-09-24 13:16:49
Closed_By jschmi102
avatar jschmi102 jschmi102 - close - 24 Sep 2024
avatar jschmi102
jschmi102 - comment - 24 Sep 2024

hi,
what do you think?
If you have an application which runs perfectly with 5 systems and does not wit one singel system. Woluld you think the application is the problem orr the failing system?

So I did the most reasonable: I used a working backup/restore of the failing sytem. And what happened? My extension is working now on this system.

Add a Comment

Login with GitHub to post a comment