@@ -667,15 +667,24 @@ export default class RapiDoc extends LitElement {
667
667
}
668
668
` ;
669
669
}
670
-
671
670
/* eslint-enable indent */
672
671
673
- observeExpandedContent ( tryCount = 0 ) {
672
+ // Cleanup
673
+ disconnectedCallback ( ) {
674
+ super . connectedCallback ( ) ;
675
+ if ( this . intersectionObserver ) {
676
+ this . intersectionObserver . disconnect ( ) ;
677
+ }
678
+ }
679
+
680
+ observeExpandedContent ( ) {
674
681
const containerEls = this . shadowRoot . querySelectorAll ( 'end-points-expanded' ) ;
682
+ /*
675
683
if (containerEls.length === 0 && tryCount < 20) {
676
684
setTimeout(() => { this.observeExpandedContent(tryCount + 1); }, 300);
677
685
return;
678
686
}
687
+ */
679
688
containerEls . forEach ( ( el ) => {
680
689
const observeTargetEls = el . shadowRoot . querySelectorAll ( '.anchor' ) ;
681
690
observeTargetEls . forEach ( ( targetEl ) => {
@@ -693,12 +702,6 @@ export default class RapiDoc extends LitElement {
693
702
if ( name === 'spec-url' ) {
694
703
if ( oldVal !== newVal ) {
695
704
this . loadSpec ( newVal ) ;
696
-
697
- // Delay observation to allow loading all the child custom-elements
698
- this . intersectionObserver . disconnect ( ) ;
699
- window . setTimeout ( ( ) => {
700
- this . observeExpandedContent ( ) ;
701
- } , 300 ) ;
702
705
}
703
706
}
704
707
super . attributeChangedCallback ( name , oldVal , newVal ) ;
@@ -788,7 +791,11 @@ export default class RapiDoc extends LitElement {
788
791
789
792
afterSpecParsedAndValidated ( spec ) {
790
793
this . resolvedSpec = spec ;
791
- if ( this . allowServerSelection === 'false' ) {
794
+ let isSelectedServerValid = false ;
795
+ if ( this . selectedServer ) {
796
+ isSelectedServerValid = ( this . selectedServer === this . serverUrl || this . resolvedSpec . servers . find ( ( v ) => ( v . url === this . selectedServer ) ) ) ;
797
+ }
798
+ if ( ! isSelectedServerValid ) {
792
799
if ( this . serverUrl ) {
793
800
this . selectedServer = this . serverUrl ;
794
801
} else if ( this . resolvedSpec && this . resolvedSpec . servers && this . resolvedSpec . servers . length > 0 ) {
@@ -798,6 +805,12 @@ export default class RapiDoc extends LitElement {
798
805
if ( ! this . apiListStyle ) {
799
806
this . apiListStyle = 'group-by-tag' ;
800
807
}
808
+
809
+ // Put it at the end of event loop, to allow loading all the child elements (must for larger specs)
810
+ this . intersectionObserver . disconnect ( ) ;
811
+ window . setTimeout ( ( ) => {
812
+ this . observeExpandedContent ( ) ;
813
+ } , 100 ) ;
801
814
this . requestUpdate ( ) ;
802
815
}
803
816
0 commit comments