Primefaces update broke HarmonyMenu - Uncaught Error: Syntax error, unrecognized expression

Forum rules
Please note that response time for technical support is within 3-5 business days.
blatra
Posts: 5
Joined: 27 Sep 2022, 13:52

27 Sep 2022, 14:07

I'm using Harmony 3.0.1 which was performing fine on Primefaces 11.0.4.
But since I upgraded to Primefaces 11.0.6 I encounter JavaScript Errors on page load while the menu tries to resore it's state from the cookie "harmony_expandeditems".
As a result the active menu entry is not highlighted and expanded submenus are not expanded anymore after page reload/switch.
I also tested Primefaces 11.0.8 which produces the same error.

There is a bug report for Primefaces 12 which describes a similar problem and states that the pipe character in the elemets ids needs to be escaped:
https://github.com/primefaces/primefaces/issues/9143

This error appears in JavaScript console in browser:

Code: Select all

12:19:51.144 Uncaught Error: Syntax error, unrecognized expression: #mainmenuform\:MainMenu__40f8676d-e2f9-4de1-8c5e-66d82e2b02ba|1
    jQuery 7
    restoreMenuState http://localhost:8080/webapp/javax.faces.resource/js/layout.js.faces?ln=harmony-layout:337
    init http://localhost:8080/webapp/javax.faces.resource/js/layout.js.faces?ln=harmony-layout:36
    Class.extend/e[d]< http://localhost:8080/webapp/javax.faces.resource/core.js.faces?ln=primefaces&v=11.0.6&e=11.0.6:24
    c http://localhost:8080/webapp/javax.faces.resource/core.js.faces?ln=primefaces&v=11.0.6&e=11.0.6:24
    createWidget http://localhost:8080/webapp/javax.faces.resource/core.js.faces?ln=primefaces&v=11.0.6&e=11.0.6:18
    cw http://localhost:8080/webapp/javax.faces.resource/core.js.faces?ln=primefaces&v=11.0.6&e=11.0.6:18
    <anonymous> http://localhost:8080/webapp/portal/home.faces:97
jquery.js.faces:2:13639
Is this a bug in harmony theme/layout or the primefaces library itself?

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

03 Oct 2022, 10:35

Interesting! I couldn't replicate it. Could you please attach a sample menu.xhtml for us to replicate? Which Harmony version are you using?

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

03 Oct 2022, 10:44

Could you please make the following change in layout.js?

Code: Select all

restoreMenuState: function() {
   ...
         var menuitem = $("#" + this.expandedMenuitems[i].replace(/:/g, "\\:").replace(/\|/g,"\\|"));    // instead of $("#" + this.expandedMenuitems[i].replace(/:/g, "\\:"))
   ...
 }

blatra
Posts: 5
Joined: 27 Sep 2022, 13:52

06 Oct 2022, 10:40

Thank you for your answer.

I'm using Harmony 3.0.1 and Primefaces 11.0.6.

Your Change fixes the error.

But now I encounter a new issue that occurs only once right after login into my application.
As a result no menu entry is highlighted right after login.

Code: Select all

10:22:18.868 Uncaught TypeError: elem.position() is undefined
    isScrolledIntoView http://localhost:8080/webapp/javax.faces.resource/js/layout.js.faces?ln=harmony-layout:379
    restoreScrollState http://localhost:8080/webapp/javax.faces.resource/js/layout.js.faces?ln=harmony-layout:365
    restoreMenuState http://localhost:8080/webapp/javax.faces.resource/js/layout.js.faces?ln=harmony-layout:348
    setTimeout handler*restoreMenuState http://localhost:8080/webapp/javax.faces.resource/js/layout.js.faces?ln=harmony-layout:347
    init http://localhost:8080/webapp/javax.faces.resource/js/layout.js.faces?ln=harmony-layout:36
    Class.extend/e[d]< http://localhost:8080/webapp/javax.faces.resource/core.js.faces?ln=primefaces&v=11.0.6&e=11.0.6:24
    c http://localhost:8080/webapp/javax.faces.resource/core.js.faces?ln=primefaces&v=11.0.6&e=11.0.6:24
    createWidget http://localhost:8080/webapp/javax.faces.resource/core.js.faces?ln=primefaces&v=11.0.6&e=11.0.6:18
    cw http://localhost:8080/webapp/javax.faces.resource/core.js.faces?ln=primefaces&v=11.0.6&e=11.0.6:18
    <anonymous> http://localhost:8080/webapp/portal/home.faces?intview=false:97
layout.js.faces:379:28
Every subsequent navigation through my portal (via clicking mainmenu buttons) is fine. The error does not arise anymore and the menu entries are highlighted as they should.

blatra
Posts: 5
Joined: 27 Sep 2022, 13:52

12 Oct 2022, 11:47

I had a look at the newest release version of harmony theme (5.0.1).
The layout.js file contains similar code:

Code: Select all

restoreMenuState: function() {
    var $this = this;
    var menucookie = $.cookie('harmony_expandeditems');
    if (menucookie) {
        this.expandedMenuitems = menucookie.split(',');
        for (var i = 0; i < this.expandedMenuitems.length; i++) {
            var id = this.expandedMenuitems[i];
            if (id) {
                var menuitem = $("#" + this.expandedMenuitems[i].replace(/:/g, "\\:"));
                menuitem.addClass('active-menuitem');

                var submenu = menuitem.children('ul');
                if(submenu.length) {
                    submenu.show();
                }
            }
        }

        setTimeout(function() {
            $this.restoreScrollState(menuitem);
        }, 100)
    }
},
I guess this version will also be affected by the issue "unrecognized expression".
Maybe the other premium themes will be affected as well.

The question is: Shall this really be fixed in potentially each and every single premium theme itself?
I mean, the source of the error seems to be that the primefaces library changed how the generated ids look like.
Maybe it's better to fix the ids in primefaces itself. I don't see any benefit from having the pipe character within the ids ...

blatra
Posts: 5
Joined: 27 Sep 2022, 13:52

14 Oct 2022, 09:49

Meanwhile primefaces contributors stated that this needs to be fixed in the themes itself.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

25 Oct 2022, 08:32

It should be fixed by the layout.js I think, it is added to our checklist for the upcoming uprades for v12.

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

31 Oct 2022, 11:39

Fixed for the next version.

Best Regards,

blatra
Posts: 5
Joined: 27 Sep 2022, 13:52

01 Nov 2022, 12:18

I'm glad to hear that it will be fixed.
Thank you for your efforts.

mert.sincan
Posts: 5281
Joined: 29 Jun 2013, 12:38

11 Nov 2022, 16:01

Glad to hear, thanks a lot for all feedback!

Best Regards,

Post Reply

Return to “Harmony - PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 3 guests