Skip to content

Commit bea9866

Browse files
committed
improved server selection process
1 parent 4766cae commit bea9866

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/rapidoc.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,24 @@ export default class RapiDoc extends LitElement {
667667
}
668668
`;
669669
}
670-
671670
/* eslint-enable indent */
672671

673-
observeExpandedContent(tryCount = 0) {
672+
// Cleanup
673+
disconnectedCallback() {
674+
super.connectedCallback();
675+
if (this.intersectionObserver) {
676+
this.intersectionObserver.disconnect();
677+
}
678+
}
679+
680+
observeExpandedContent() {
674681
const containerEls = this.shadowRoot.querySelectorAll('end-points-expanded');
682+
/*
675683
if (containerEls.length === 0 && tryCount < 20) {
676684
setTimeout(() => { this.observeExpandedContent(tryCount + 1); }, 300);
677685
return;
678686
}
687+
*/
679688
containerEls.forEach((el) => {
680689
const observeTargetEls = el.shadowRoot.querySelectorAll('.anchor');
681690
observeTargetEls.forEach((targetEl) => {
@@ -693,12 +702,6 @@ export default class RapiDoc extends LitElement {
693702
if (name === 'spec-url') {
694703
if (oldVal !== newVal) {
695704
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);
702705
}
703706
}
704707
super.attributeChangedCallback(name, oldVal, newVal);
@@ -788,7 +791,11 @@ export default class RapiDoc extends LitElement {
788791

789792
afterSpecParsedAndValidated(spec) {
790793
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) {
792799
if (this.serverUrl) {
793800
this.selectedServer = this.serverUrl;
794801
} else if (this.resolvedSpec && this.resolvedSpec.servers && this.resolvedSpec.servers.length > 0) {
@@ -798,6 +805,12 @@ export default class RapiDoc extends LitElement {
798805
if (!this.apiListStyle) {
799806
this.apiListStyle = 'group-by-tag';
800807
}
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);
801814
this.requestUpdate();
802815
}
803816

0 commit comments

Comments
 (0)