@@ -76,6 +76,7 @@ export class AppTree {
7676 ready : Promise < void > ;
7777 ready_resolve ! : ( ) => void ;
7878 resolved : boolean = false ;
79+ #hidden_on_startup: Set < number > = new Set ( ) ;
7980
8081 constructor (
8182 components : ComponentMeta [ ] ,
@@ -228,7 +229,8 @@ export class AppTree {
228229 ( node ) =>
229230 untrack_children_of_closed_accordions_or_inactive_tabs (
230231 node ,
231- this . components_to_register
232+ this . components_to_register ,
233+ this . #hidden_on_startup
232234 )
233235 ] ) ;
234236 }
@@ -352,9 +354,9 @@ export class AppTree {
352354 : null ,
353355 key : component . key ,
354356 rendered_in : component . rendered_in ,
355- documentation : component . documentation
357+ documentation : component . documentation ,
358+ original_visibility : processed_props . shared_props . visible
356359 } ;
357-
358360 return node ;
359361 }
360362
@@ -475,7 +477,7 @@ export class AppTree {
475477 this . root = this . traverse ( this . root ! , [
476478 ( node ) => {
477479 if ( node . id === id ) {
478- update_visibility ( node , true ) ;
480+ make_visible_if_not_rendered ( node , this . #hidden_on_startup ) ;
479481 }
480482 return node ;
481483 } ,
@@ -484,14 +486,15 @@ export class AppTree {
484486 }
485487}
486488
487- function update_visibility (
489+ function make_visible_if_not_rendered (
488490 node : ProcessedComponentMeta ,
489- visible : boolean
491+ hidden_on_startup : Set < number >
490492) : void {
491- node . props . shared_props . visible = visible ;
493+ node . props . shared_props . visible = hidden_on_startup . has ( node . id )
494+ ? true
495+ : node . props . shared_props . visible ;
492496 node . children . forEach ( ( child ) => {
493- child . props . shared_props . visible = visible ;
494- update_visibility ( child , visible ) ;
497+ make_visible_if_not_rendered ( child , hidden_on_startup ) ;
495498 } ) ;
496499}
497500
@@ -626,7 +629,6 @@ function set_visibility_for_updated_node(
626629) : ProcessedComponentMeta {
627630 if ( node . id == id ) {
628631 node . props . shared_props . visible = visible ;
629- update_visibility ( node , visible ) ;
630632 }
631633 return node ;
632634}
@@ -653,17 +655,31 @@ function untrack_children_of_invisible_parents(
653655 return node ;
654656}
655657
658+ function mark_component_invisible_if_visible (
659+ node : ProcessedComponentMeta ,
660+ hidden_on_startup : Set < number >
661+ ) : ProcessedComponentMeta {
662+ if ( node . props . shared_props . visible === true ) {
663+ hidden_on_startup . add ( node . id ) ;
664+ node . props . shared_props . visible = false ;
665+ }
666+ node . children . forEach ( ( child ) => {
667+ mark_component_invisible_if_visible ( child , hidden_on_startup ) ;
668+ } ) ;
669+ return node ;
670+ }
671+
656672function untrack_children_of_closed_accordions_or_inactive_tabs (
657673 node : ProcessedComponentMeta ,
658- components_to_register : Set < number >
674+ components_to_register : Set < number > ,
675+ hidden_on_startup : Set < number >
659676) : ProcessedComponentMeta {
660677 // Check if the node is an accordion or tabs
661678 if ( node . type === "accordion" && node . props . props . open === false ) {
662679 _untrack ( node , components_to_register ) ;
663680 if ( node . children ) {
664681 node . children . forEach ( ( child ) => {
665- if ( child . props . shared_props . visible === true )
666- update_visibility ( child , false ) ;
682+ mark_component_invisible_if_visible ( child , hidden_on_startup ) ;
667683 } ) ;
668684 }
669685 }
@@ -675,13 +691,7 @@ function untrack_children_of_closed_accordions_or_inactive_tabs(
675691 ( node . props . props . selected || node . props . props . initial_tabs [ 0 ] . id )
676692 ) {
677693 _untrack ( child , components_to_register ) ;
678- if ( child . children ) {
679- child . children . forEach ( ( grandchild ) => {
680- if ( grandchild . props . shared_props . visible === true ) {
681- update_visibility ( grandchild , false ) ;
682- }
683- } ) ;
684- }
694+ mark_component_invisible_if_visible ( child , hidden_on_startup ) ;
685695 }
686696 } ) ;
687697 }
0 commit comments