Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-5000

Inefficient DOM updates for link labels

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • 10.0.0
    • 9.6.0
    • Components
    • Security Level: Jimmy

      Steps to Reproduce

      run the attached example zk-5000.zul

      case A) click a plus icon without scrolling down (on a row with index below 50)

      case B) click a plus icon after scrolling down ... (on a row with index above 50)

      Current Result

      case A)

      1. the new row is added
      2. after a delay the row indices in the first column update

      profiling result shows a dedicated block updating the link labels (rerendering the whole widget's DOM elements)

      case B)

      1. the new row is added empty (white row)
      2. after a delay the row indices in the first column update
      3. after another delay the empty row is filled with the new row contents

      profiling result now show 2 addtional blocks updating the link labels (rerendering the whole widget's DOM elements) and rendering the row contents

      Expected Result

      avoid delayed updates, avoid rebuilding whole widget's DOM structure in case only single properties such as label text changes

      Debug Information

      https://github.com/zkoss/zk/blob/v9.6.0/zul/src/archive/web/js/zul/LabelImageWidget.js#L31-L34

      LabelImageWidget rerenders the whole DOM content even when only the label text changes.

      Workaround

      override the setLabel in zul.wgt.A:
      below a naive approach (which doesn't cover all possible edge cases) to find/set the textNode.nodeValue directly

      		setLabel : function(label) {
      		    if(this._label === label) {
      		        return;
      		    }
      		    this._label = label;
      		    if(this.desktop) {
      		        var textNode = Array.prototype.find.call(this.$n().childNodes, node => node.nodeType === Node.TEXT_NODE);
      		        textNode.nodeValue = label;
      		    }
      		}
      

        1. screenshot-1.png
          screenshot-1.png
          126 kB
        2. screenshot-2.png
          screenshot-2.png
          71 kB
        3. zk-5000.zul
          2 kB

            gordonhsu gordonhsu
            cor3000 cor3000
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: