Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-57714

Javascript eval fails randomly when a portlet loads with AJAX

    Details

    • Story Points:
      12

      Description

      When a portlet is added to a page using AJAX like:

      • Add a portlet to a page
      • When a page is displayed, the portlet is loaded asynchronously

      There could be a js error in somes conditions. As an exemple i will take the Asset Publisher portlet. This one uses nav-item taglib to display a dropdown button in the menu (Add a content). This taglib contains script that manages dropdown for mobile devices:

      A.Event.defineOutside('touchend');
      
      var container = A.one('#<%= id %>');
      
      container.one('a').on(
      	'gesturemovestart',
      	function(event) {
      

      Tech informations: It fails sometimes here because container is null. This is due to the addHTML method in /html/js/portlet.js which uses A.ParseContent. The problem here is that the html is inserted sometimes after js eval (because ParseContent uses aync queue to call globalEval method).

      Functional informations; I'm afraid that I don't have a test scenario for this. You can try to add Asset Publisher portlet to a page and maybe you will get this error. A slow computer could help to get this more often. This bug is quite annoying because when it happens you can't click anywhere on the page (like dockbar, portlet configuration, etc...).

      I fixed this bug but I can't make a pull request, so here's my diff:

      index ed7df4a..c060045 100644
      --- a/app/dev/liferay/tomcat/webapps/ROOT/html/js/liferay/portlet.js
      +++ b/app/dev/liferay/tomcat/webapps/ROOT/html/js/liferay/portlet.js
      @@ -263,8 +263,6 @@
       
                                      var portletBound = A.Node.create('<div></div>');
       
      -                               portletBound.plug(A.Plugin.ParseContent);
      -
                                      portletBound.setContent(html);
       
                                      portletBound = portletBound.one('> *');
      @@ -276,7 +274,11 @@
                                      portletBound.portletId = portletId;
       
                                      placeHolder.hide();
      -                               placeHolder.placeAfter(portletBound);
      +                               placeHolder.insert(portletBound, 'after');
      +                               
      +                               var tmpNode = A.Node.create('<div></div>');
      +                               tmpNode.plug(A.Plugin.ParseContent);
      +                               tmpNode.ParseContent.parseContent(html);
       
                                      placeHolder.remove();
      

      Regards,
      Kevin.

        Attachments

          Activity

            People

            • Assignee:
              haoliang.wu Haoliang Wu (Inactive)
              Reporter:
              kevin.musarella Kevin Musarella
              Participants of an Issue:
              Recent user:
              Esther Sanz
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                4 years, 1 week, 5 days ago

                Packages

                Version Package
                6.2.X EE
                7.0.0 Alpha 2