Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-15861

Bad usage of #define() in AlertsMenuUIX cause some code to be executed twice

    Details

    • Difficulty:
      Unknown
    • Documentation:
      N/A
    • Documentation in Release Notes:
      N/A
    • Similar issues:

      Description

      See https://github.com/xwiki/xwiki-platform/blob/053f0a2757cea18a5916632a58c6046ba61954cd/xwiki-platform-core/xwiki-platform-alerts/xwiki-platform-alerts-ui/src/main/resources/XWiki/Alerts/Code/AlertsMenuUIX.xml#L137

      When you do

      #define($something)
        Some content : $someVar
      #end
      #set ($someVar = "hello")
      $something
      #set ($someVar = "world")
      $something
      

      will display:

      Some content: hello
      Some content: world
      

      So it means the $something is evaluated each time we call it. It's a kind of macro.

      In the alert menu uix, we first look if the defined variable is blank and then we display it. But because we don't cache the rendering of the defined variable, it is rendered twice.

      In the case of the notifications, this can become costly.

        Attachments

          Activity

            People

            • Assignee:
              gdelhumeau Guillaume Delhumeau
              Reporter:
              gdelhumeau Guillaume Delhumeau
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: