@@ -219,12 +219,11 @@ export default class FileTree {
219219 queueMicrotask ( ( ) => toggle ( ) ) ;
220220 }
221221
222- const defineCollapsibleAccessors = ( $el ) => {
223- Object . defineProperties ( $el , {
222+ const defineCollapsibleAccessors = ( $el , { includeTitle = true } = { } ) => {
223+ const properties = {
224224 collapsed : { get : ( ) => $wrapper . classList . contains ( "hidden" ) } ,
225225 expanded : { get : ( ) => ! $wrapper . classList . contains ( "hidden" ) } ,
226226 unclasped : { get : ( ) => ! $wrapper . classList . contains ( "hidden" ) } , // Legacy compatibility
227- $title : { get : ( ) => $title } ,
228227 $ul : { get : ( ) => $content } ,
229228 fileTree : { get : ( ) => childTree } ,
230229 refresh : {
@@ -236,12 +235,18 @@ export default class FileTree {
236235 collapse : {
237236 value : ( ) => $wrapper . classList . contains ( "hidden" ) || toggle ( ) ,
238237 } ,
239- } ) ;
238+ } ;
239+
240+ if ( includeTitle ) {
241+ properties . $title = { get : ( ) => $title } ;
242+ }
243+
244+ Object . defineProperties ( $el , properties ) ;
240245 } ;
241246
242247 // Keep nested folders compatible with the legacy collapsableList API.
243248 defineCollapsibleAccessors ( $wrapper ) ;
244- defineCollapsibleAccessors ( $title ) ;
249+ defineCollapsibleAccessors ( $title , { includeTitle : false } ) ;
245250
246251 return $wrapper ;
247252 }
@@ -293,11 +298,7 @@ export default class FileTree {
293298 * Clear all rendered content
294299 */
295300 clear ( ) {
296- // Destroy all child trees
297- for ( const childTree of this . childTrees . values ( ) ) {
298- childTree . destroy ( ) ;
299- }
300- this . childTrees . clear ( ) ;
301+ this . destroyChildTrees ( ) ;
301302
302303 if ( this . virtualList ) {
303304 this . virtualList . destroy ( ) ;
@@ -334,6 +335,16 @@ export default class FileTree {
334335 }
335336 }
336337
338+ /**
339+ * Destroy all expanded child trees and clear their references.
340+ */
341+ destroyChildTrees ( ) {
342+ for ( const childTree of this . childTrees . values ( ) ) {
343+ childTree . destroy ( ) ;
344+ }
345+ this . childTrees . clear ( ) ;
346+ }
347+
337348 /**
338349 * Append a new entry to the tree
339350 * @param {string } name
@@ -368,6 +379,7 @@ export default class FileTree {
368379 this . virtualList . setItems ( this . entries ) ;
369380 } else {
370381 // Fragment mode: re-render
382+ this . destroyChildTrees ( ) ;
371383 this . container . innerHTML = "" ;
372384 this . renderWithFragment ( ) ;
373385 }
0 commit comments