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

zEmbedded doesn't clean client-side object and references on destroy

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 9.6.0
    • 9.0.0
    • ZK Client Engine
    • Security Level: Jimmy
    • None

      Steps to Reproduce

      Load a zul page containing a component with an ID:

      <div id="myComp"/>

      Load the same zul page again using the same target

      The zEmbedded.load will invoke zEmbedded.destroy, which clear up the DOM tree, but doesn't destroy or detach widgets.

      From client console, access the widget using zk.$("$myComp")

      Current Result

      The returned widget is the first instance (no longer attached to DOM)

      calling zk.$("$myComp").$n() returns a detached DOM node no longer available in the page's DOM tree

      Expected Result

      zEmbedded destroy should also destroy widgets

      Debug Information

       

      Workaround

      call zAu.cmd1.rm(page) during destroy

      var originalDestroy = zEmbedded.destroy;
      zEmbedded.destroy = function (domId, skipError) {
              var page
      	if (typeof zk === 'undefined') {
      				if (skipError) return;
      				else throw new Error('zk is not loaded.');
      			}
      			var n = document.getElementById(domId);
      			if (n) {
      				page = n.hasChildNodes() ? zk.$(n.firstChild) : null;
      				
      			}
      
      			var result = originalDestroy.apply(this,arguments);
      				if (page) {
      					zAu.cmd1.rm(page)
      				}
      	return result;
      }
      
      function loadZk(){
      	zEmbedded.load('zkapp', 'http://localhost:8080/zkembedded-app/index.zul?myparam=init-from-client-side')
      		.then(function(result) {
      			var myWin = result.widget;
      			myWin.desktop.listen({onBeforeDestroy:function(){
      				console.log("before destroy this desktop")
      			}});
      			
      		})
      		.catch(function(error) {
      			console.error(error);
      		});
      }
      

            DevChu DevChu
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: