[Navigation Tree] Race condition on checking document readystate (#3430)

* checking if state is already ready, as this is a subcomponent, that could be the case

* optimizing readystate checks
This commit is contained in:
Jamie V 2020-10-07 16:38:54 -07:00 committed by GitHub
parent 87a45de05b
commit 6923f17645
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 12 deletions

View File

@ -265,11 +265,7 @@ export default {
async mounted() {
// only reliable way to get final tree top margin
document.onreadystatechange = () => {
if (document.readyState === "complete") {
this.mainTreeTopMargin = this.getElementStyleValue(this.$refs.mainTree, 'marginTop');
}
};
this.readyStateCheck();
this.backwardsCompatibilityCheck();
@ -323,8 +319,21 @@ export default {
destroyed() {
window.removeEventListener('resize', this.handleWindowResize);
this.stopObservingAncestors();
document.removeEventListener('readystatechange', this.setTreeTopMargin);
},
methods: {
readyStateCheck() {
if (document.readyState !== 'complete') {
document.addEventListener('readystatechange', this.setTreeTopMargin);
} else {
this.setTreeTopMargin();
}
},
setTreeTopMargin() {
if (document.readyState === 'complete') {
this.mainTreeTopMargin = this.getElementStyleValue(this.$refs.mainTree, 'marginTop');
}
},
updateVisibleItems() {
if (this.updatingView) {
return;

View File

@ -122,13 +122,7 @@ export default {
let objectComposition = this.openmct.composition.get(this.node.object);
// only reliable way to get final item height
document.onreadystatechange = () => {
if (document.readyState === "complete") {
if (this.shouldEmitHeight) {
this.$emit('emittedHeight', this.$el.offsetHeight);
}
}
};
this.readyStateCheck();
this.domainObject = this.node.object;
let removeListener = this.openmct.objects.observe(this.domainObject, '*', (newObject) => {
@ -144,8 +138,21 @@ export default {
},
destroyed() {
this.openmct.router.off('change:path', this.highlightIfNavigated);
document.removeEventListener('readystatechange', this.emitHeight);
},
methods: {
readyStateCheck() {
if (document.readyState !== 'complete') {
document.addEventListener('readystatechange', this.emitHeight);
} else {
this.emitHeight();
}
},
emitHeight() {
if (this.shouldEmitHeight && document.readyState === 'complete') {
this.$emit('emittedHeight', this.$el.offsetHeight);
}
},
buildPathString(parentPath) {
return [parentPath, this.openmct.objects.makeKeyString(this.node.object.identifier)].join('/');
},