Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
How to properly unload and kill a web component?

im having a simple web component running on my page. By a button click i simply remove the element expecting that the element and the class behind it is getting killed. But actually it keeps running, for example event listeners are still running even after removing it from the DOM.

This is how i add it to the DOM and make it load:

import { LightningElement, createElement } from 'lwc';
import App from 'my/app';

export default class App extends LightningElement {
  ...
  const appinner = createElement('my-app', { is: App });
  document.body.appendChild(app);
  ...
}

Then i simply remove it by this:

const app = document.querySelector('my-app');
app.remove(); // or app.parentNode.removeChild(app);

Everything in my "App" class is still running even when its gone. How can i really make it unload (or deconstruct) or even kill so no logic keeps running.

Update: Missed to mention i am using LWC library from lwc.dev. And the proper way of injecting an element is described here: Link

Update2: Added more code to show how its really done using the LWC.dev library

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda