Opened 11 years ago

Closed 11 years ago

#7959 closed defect (duplicate)

Removing a tree and re-adding it to a ContentPane fails in 1.2.0

Reported by: spidey2099 Owned by: Sam Foster
Priority: high Milestone: tbd
Component: Dijit Version: 1.2.0
Keywords: tree, contentpane, readding fails Cc:
Blocked By: Blocking:

Description (last modified by bill)

In my code, I am creating a tree and when something changes in a critical section of my application, I am removing the old tree and adding a new one. The tree is attached to a ContentPane? or an ExpandoPane?. Well the ContenPane?.destroyDescendants() function in 1.2-0b1 was a direct call to it's parent - dijit._Widget.js - which does this:

        destroyDescendants: function(/*Boolean?*/ preserveDom){
                // summary:
                //              Recursively destroy the children of this widget
and their
                //              descendants.
                // preserveDom:
                //              If true, the preserveDom attribute is passed to
all descendant
                //              widget's .destroy() method. Not for use with _Te
mplated
                //              widgets.

                // TODO: should I destroy in the reverse order, to go bottom up?
                dojo.forEach(this.getDescendants(), function(widget){
                        if(widget.destroy){
                                widget.destroy(preserveDom);
                        }
                });

However in 1.2.0 and later, the ContentPane? does have a destroyDescendants() function which does this:

        destroyDescendants: function(){
                // summary:
                //              Destroy all the widgets inside the ContentPane a
nd empty containerNode

                // Make sure we call onUnload
                // TODO: this shouldn't be called when we are simply destroying
a "Loading..." message
                this._onUnloadHandler();

                // dojo.html._ContentSetter keeps track of child widgets, so we
should use it to
                // destroy them.
                //
                // Only exception is when those child widgets were specified in
original page markup
                // and created by the parser (in which case _ContentSetter doesn
't know what the widgets
                // are).  Then we need to call Widget.destroyDescendants().
                //
                // Note that calling Widget.destroyDescendants() has various iss
ues (#6954),
                //  namely that popup widgets aren't destroyed (#2056, #4980)
                // and the widgets in templates are destroyed twice (#7706)
                var setter = this._contentSetter;
                if(setter){
                        // calling empty destroys all child widgets as well as e
mptying the containerNode
                        setter.empty();
                }else{
                        this.inherited(arguments);
                        dojo.html._emptyNode(this.containerNode);
                }
        },

With this new change, if I remove and re-add a tree to a ContentPane, it fails to render.

Change History (5)

comment:1 Changed 11 years ago by Adam Peller

Owner: set to Sam Foster

comment:2 Changed 11 years ago by Josh Trutwin

Is there a reason why dijit.layout.ContentPane? would not call this.destroyRecursive() (or destroyDescendants?) from within this._setContentAttr() in dijit.layout.ContentPane?? Assuming you get new content either via setContent, setHref why not destroy what is already in the cpane?

I think that might fix this issue and other cpane related issues related to this bug. Not sure tho....

please add josh@… to CC list.

Thanks,

Josh

comment:3 Changed 11 years ago by Adam Peller

test

comment:4 Changed 11 years ago by ben hockey

see #7784

comment:5 Changed 11 years ago by bill

Description: modified (diff)
Resolution: duplicate
Status: newclosed

Yup, this is a dup of #7784. I'll add Josh to the CC there.

Note: See TracTickets for help on using tickets.