View Full Version : TreePanel control says registered with Ext.dd.ScrollManager

3 Apr 2007, 2:08 PM
When I load a tree control inside of a layout and then remove it, there are "parts hanging around" causing errors.

Here is the setup and the error.

I load a ContentPanel object into a LayoutRegion via Ajax. The object has the following code that builds tree on init. I unload the object and remove the related ContentPanel it was loaded in, etc. but when I resize the parent layout, it gives a message that says "Unspecified Error"

var Tree = Ext.tree;
var tree = new Tree.TreePanel('somelabel'), {
containerScroll: true,
dropConfig: {appendOnly:true}
new Tree.TreeSorter(tree, {folderSort:true});
me.root = new Tree.TreeNode({id:'home', text:'YUI-Demo', cls: 'folder'});
tree.on('click', this.nodeClicked );

When you debug of course you are 100 layers deep in the middle of an event call, but I chopped the problem in 1/2 until I determined that the problem is as follows:

The following code in the Ext.tree.TreePanel - render function registers its el with the Scrollmanager using the Ext.dd.ScrollManager.register(this.el); call.

render : function(){

this.container = this.el.createChild({tag:"ul",
cls:"x-tree-root-ct " +
(this.lines ? "x-tree-lines" : "x-tree-no-lines")});

Ext.dd.ScrollManager.register(this.el); //root cause - no unregister related to this

Why this turns into an error:
Then the Ext.dd.ScrollManager onFire event kicks off....

in the process is calls ...

This function ends up calling the following line which causes the error due to no related region (it was removed along with the ContentPanel and object - just this stray div hanging around).

els[id]._region = els[id].getRegion();

In my own master objects unload function if the closing object has a tree then I "manually" unregister it - which fixed the error.

It seems odd that something would register itself but not unregister itself.

Am I doing something wrong here to not have the tree unregister on its own? Is there a call I can make that will unregister and remove items like this as needed that I do not know of (i.e. destroy() )?



3 Apr 2007, 4:52 PM
There is no destroy method for a tree. Unfortunately, that means it doesn't do automatic clean up so you will need to do clean up yourself.

In a future release I am sure we will add automatic clean up.

3 Apr 2007, 5:16 PM
Many hours are spent chasing down what was needed here. When the documentation comes out, can you include cleanup items that are internal? It seems like making one function and documenting that would be easier though. The only way I knew this was happening was to read the code and find out the TreePanel is registering itself and not cleaning up. And finding that out was tough - the error was in an event fired after the object is closed - from the scroll manger. Think about how hard that is to find.

This is why I added this to the bug forum - a crash in the middle of region resize that happen on internal code due to internal code is a bug to most people. Anyone that puts a tree in a layout and them removes everything will hit this and be glad to know what cleanup item they need to be chasing.

Thanks for the reply.

Great tool, it should sell like hotcakes.

3 Apr 2007, 5:29 PM
When creating a component as complex as a tree with DND, there are many things that take place that need to be cleaned up (not just the ScrollManager issue).

component != element

Simply overwriting a component's HTML or removing it's DOM node and expecting everything to just magically disappear IMO is a bad assumption. In most instances, there's really no way for the component to even know it no longer exists in the DOM.

You are 100% correct though, who wants to go hunt all that stuff down?! In most instances, Ext does provide automatic clean up functionality for you. I'm sure the Tree will have this as well soon.

3 Apr 2007, 5:54 PM
Jack, I wrote a special process to track all loaded objects and content panels and a master cleanup object. I am not just killing the dom and then complaining that it broke.

Please consider adding a thread on "things you need to cleanup" for items like this until such time that every component has a destroy method that does needed cleanup items.

Again, thanks for the active replies.