Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-11116

JSI script doesn't always trigger in a browser with multiple components included

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • Dynamic Include 3.3.0
    • None
    • Extensions
    • None

    Description

      Using Javascript includes (JSI) in Sling Dynamic Include 3.3.0 on a page with multiple levels of inclusions the components deeper in the tree does not always get fetched and included into the DOM.

      Page
        -> ComponentA
        -> JSI ComponentB
          -> JSI ComponentC
      

      ComponentC may not always be fetched and included in the DOM. This is an issue in cases where authors add multiple components, defined in the SDI include-filter.config.resource-types configuration, inside each other.

      The cause seem to be the usage of innerHTML to replace content in the DOM.

      if (xhr.status >= 200 && xhr.status < 300) {
        var elemId = document.getElementById('${uniqueId}');
        if (elemId) elemId.innerHTML = xhr.responseText;
      }
      

      innerHTML does not trigger code in <script> sections:
      https://www.w3.org/TR/2008/WD-html5-20080610/dom.html#innerhtml0

      script elements inserted using innerHTML do not execute when they are inserted.

      This can be avoided by using appendChild and wrapping the content in a div tag:

      if (elemId) {
        var resultDiv = document.createElement('div');
        resultDiv.innerHTML = xhr.responseText;
        elemId.innerHTML = '';
        elemId.appendChild(resultDiv);
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            jar-miracle Jakob Rosenlund
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 3h
                3h
                Remaining:
                Time Spent - 40m Remaining Estimate - 2h 20m
                2h 20m
                Logged:
                Time Spent - 40m Remaining Estimate - 2h 20m
                40m