Fix logs view existing multiple times (#1000)

* Fix terminal DOM existing multiple times

When switching between the tasks/config/changed files tabs in the build
view, the DOM for the log xterm would be inserted multiple times,
causing the current terminal to be shifted down weirdly.
This fixes this behavior by cleaning any custom DOM before the log is
unmounted.

* Use ref
This commit is contained in:
Florian Märkl 2022-06-25 19:52:37 +02:00 committed by GitHub
parent 716d55a370
commit 3f73d5bf53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -167,11 +167,16 @@ export default defineComponent({
fitAddon.value.fit();
}
const unmounted = ref(false);
onMounted(async () => {
term.value.loadAddon(fitAddon.value);
term.value.loadAddon(new WebLinksAddon());
await nextTick(() => {
if (unmounted.value) {
// need to check if unmounted already because we are async here
return;
}
const element = document.getElementById('terminal');
if (element === null) {
throw new Error('Unexpected: "terminal" should be provided at this place');
@ -214,9 +219,15 @@ export default defineComponent({
);
onBeforeUnmount(() => {
unmounted.value = true;
if (stream.value) {
stream.value.close();
}
const element = document.getElementById('terminal');
if (element !== null) {
// Clean up any custom DOM added in onMounted above
element.innerHTML = '';
}
window.removeEventListener('resize', resize);
});