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

infinite loop when firing an event on a detached widget

XMLWordPrintable

      Steps to Reproduce

      <zk>
        <button id="btn"/>
      </zk>
      

      execute in the console

      var b = zk.$('$btn'); 
      b.detach();
      b.fire('onCustomEvent', null, {toServer: true});
      

      Current Result

      browser tab gets stuck at 100% CPU in an infinite loop

      Expected Result

      fail with a (meaningful) error instead due to incorrect usage

      Debug Information

      the infinite loop happens here:
      https://github.com/zkoss/zk/blob/v9.6.0/zk/src/archive/web/js/zk/au.ts#L139-L142

      In the latest 9.6.1-FL-2021-09-28 the infinite loop code is not reached, instead NOTHING happens, no indication of an error (maybe also not the best outcome)

      the potential infinite loop code is still there and needs to fail if called incorrectly

      Workaround

      don't fire events on detached components.
      e.g. check manually whether the current widget is detached before firing the event

      var b = zk.$('$btn'); 
      b.detach(); 
      if(b.parent && b.desktop) {
         b.fire('onCustomEvent', null, {toServer: true});
      }
      

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

              Created:
              Updated:
              Resolved: