No Code Attached Yet Information Required
avatar hikashop-nicolas
hikashop-nicolas
6 Jan 2022

Steps to reproduce the issue

Install HikaShop Starter (free via the "Install from web" interface)
Go in the Extensions>HikaShop>Orders menu
Create a new order with the "new" button
Click on the "invoice" button
It opens a popup with the invoice of the order and there is now a javascript error in the console of the browser.
https://i.imgur.com/DEktYsL.png

Expected result

No error in the console

Actual result

The error below in the console of the browser:
Uncaught TypeError: Cannot read properties of null (reading 'children') on line 25 of media/templates/administrator/atum/js/template.js

System information (as much as possible)

Joomla 4 latest version + HikaShop latest version

Additional comments

The issue was first reported to us here:
https://www.hikashop.com/forum/orders-management/903764-product-custom-fields-on-orders-invoices.html#338382

The error happens because the code in template.js is looking for header divs to process them. However, in modals these elements are not displayed by the template.
I don't have the error when I check the popups of joomla pages as template.js is not loaded there.
I suppose that this happens because HikaShop loads some elements (like jquery or bootstrap ?) in its popups which leads to the template.js file being loaded even though it's not needed.

It's possible for us to fix this by adding such HTML in the modal views:

<div id="header"><div class="header-title"></div><div class="header-items"></div></div><div id="header-more-items"></div>

There are actually several javascript errors:

  • one on .children as reported
  • one on querySelectorAll two lines below on line 27
  • and one on getBoundingClientRect on next line ( the 28 )
    and thus all that HTML is necesssary to remove all the errors from the loading of the popup.

However, I think it would be better to modify the javascript of the template to check that the elements are there before processing them.
But maybe someone knowing better how atum works would have another idea ?

avatar hikashop-nicolas hikashop-nicolas - open - 6 Jan 2022
avatar joomla-cms-bot joomla-cms-bot - change - 6 Jan 2022
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 6 Jan 2022
avatar hikashop-nicolas hikashop-nicolas - change - 6 Jan 2022
The description was changed
avatar hikashop-nicolas hikashop-nicolas - edited - 6 Jan 2022
avatar hikashop-nicolas hikashop-nicolas - change - 6 Jan 2022
The description was changed
avatar hikashop-nicolas hikashop-nicolas - edited - 6 Jan 2022
avatar hikashop-nicolas hikashop-nicolas - change - 6 Jan 2022
The description was changed
avatar hikashop-nicolas hikashop-nicolas - edited - 6 Jan 2022
avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

The error happens because the code in template.js is looking for header divs to process them. However, in modals these elements are not displayed by the template.

That's the wrong assumption, the script is not loaded for the modals if the correct entry point is set. In the core wherever there's a modal the iframe URL is always pointing to ?tmpl=component so that the modal will not load unneeded code:

Here's one example:

'url' => Route::_('index.php?option=com_languages&view=multilangstatus&tmpl=component'),

And the relative code that disables the script in the component.php entry point:

// No template.js for modals
$wa->disableScript('template.atum');

In short, this is not a core problem...

avatar hikashop-nicolas
hikashop-nicolas - comment - 6 Jan 2022

Thanks for your answer.

I understand what you're saying, however, the URL of the modal I'm pointing at also has &tmpl=component in it. Here is a screenshot of the content of the modal loaded directly :
https://i.imgur.com/AE8OzWo.png
You can see that the URL has the &tmpl=component parameter but there is the JS error on the template.js file in the console.

Nevertheless, the file media/templates/administrator/atum/js/template.js is still in the header.
And I don't know how that is possible nor what I should do or where to look to find what is doing that. Do you have an idea ?
I tried adding

	$wa = JFactory::getApplication()->getDocument()->getWebAssetManager();
	$wa->disableScript('template.atum');

to the view displaying the invoice modal in HikaShop, but it doesn't change anything, which is normal since the component.php file of the template is processed after the view file and already does it.

On another note, wouldn't adding the extra check in the javascript be a good practice in case something unexpected happens on the page and the HTML is not there ?

avatar Fedik
Fedik - comment - 6 Jan 2022

However, I think it would be better to modify the javascript of the template to check that the elements are there before processing them.

As you already know the fix, please make a PR

avatar hikashop-nicolas
hikashop-nicolas - comment - 6 Jan 2022

However, I think it would be better to modify the javascript of the template to check that the elements are there before processing them.

As you already know the fix, please make a PR

Well, I wanted to discuss if this was a good idea or not as I'm not familiar with atum or that javascript.

avatar Fedik
Fedik - comment - 6 Jan 2022

Some more of if() should not be bad :)

avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

You can see that the URL has the &tmpl=component parameter but there is the JS error on the template.js file in the console.

if that’s the case then this is a bug in the atum template. In the component.php the template.js should be ignored

avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

@hikashop-nicolas Ok the problem is on your side, the URL needs to be like:
http://host.local:8080/joomla-cms/administrator/index.php?option=com_hikashop&ctrl=order&task=invoice&tmpl=component&type=full&order_id=1
but it is like http://host.local:8080/joomla-cms/administrator/index.php?option=com_hikashop&amp;ctrl=order&amp;task=invoice&amp;tmpl=component&amp;type=full&amp;order_id=1

the &amp; parts are breaking the bank here

Screenshot 2022-01-06 at 20 33 35

Screenshot 2022-01-06 at 20 33 43

you should escape the url only if it’s going to be displayed in the browser, for php usage keep the non escaped

avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

I guess this can be closed

avatar hikashop-nicolas
hikashop-nicolas - comment - 6 Jan 2022

The URL is not the problem. If you check my previous screenshot, the javascript error is there in the console even though the URL has & and not & in the address bar of the browser.
Are you saying you don't have the error on your end when you look at the invoice ?
In that case, it must mean that there is something else at play which ends up loading the template.js file for some reason on my end and not on yours.

But as Fedik said, I think it's a good idea to add some extra checks in the javascript of the template. I'll look at submitting a PR.

avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

@hikashop-nicolas check your HTML of the iframe. Copy the URL to another browser tab and then edit it and replace the &amp; with &

Fixing the template.js won't fix anything on your side as you're loading the complete backend (menu, top bar, etc)

avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

The URL is not the problem. If you check my previous screenshot, the javascript error is there in the console even though the URL has & and not & in the address bar of the browser.

Pfff that's the URL of the top page I'm talking about the URL of the iframe Check my images, these are the URLs of the IFRAME, the first one is what your component produces (which is completely wrong) and the 2nd one is what would work...

Seriously there's nothing wrong with the core here, you're escaping the URL when you shouldn't, that's all

avatar hikashop-nicolas
hikashop-nicolas - comment - 6 Jan 2022

No, that's not the URL of the top page, it's the URL of the iframe that I had already openned in another tab.
Please look at my screenshot again: https://i.imgur.com/AE8OzWo.png
The screenshot is of the iframe that I openned in another tab. I did it like that especially to show you that the URL of the iframe is correct and I still have the js error.
If the parameters of the URL for the popup had amp; then the popup would display the dashboard of HikaShop with the Joomla menus and everything, like in your screenshot, with the URL with the amp;.
But as you can see if you look at the popup, it doesn't show the dashboard and the joomla menus in it, only the invoice.

Also if you check the HTML of the top page where the button is, the URL is correct, without the amp; , see here: https://i.imgur.com/h3hTCoT.png
So I'm not sure where you're getting the amp; in your URL from.

avatar dgrammatiko
dgrammatiko - comment - 6 Jan 2022

@hikashop-nicolas you can add some breakpoints both in the index.php and the component.php to debug this. I already told you what's failing and it's not component.php as that entry point DOES NOT LOAD the template.js...

avatar hikashop-nicolas
hikashop-nicolas - comment - 7 Jan 2022

Yes, I understood that, and I thank you for that explanation.

avatar alikon
alikon - comment - 10 Jan 2022

can this be closed then ? @hikashop-nicolas

avatar Quy Quy - change - 11 Jan 2022
Labels Added: Information Required
avatar Quy Quy - labeled - 11 Jan 2022
avatar Quy Quy - change - 18 Jan 2022
Status New Closed
Closed_Date 0000-00-00 00:00:00 2022-01-18 12:53:40
Closed_By Quy
avatar Quy Quy - close - 18 Jan 2022

Add a Comment

Login with GitHub to post a comment