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

205
Visualizações
WebComponent setter not triggered if defer is used

I recently noticed that a setter in a web component is not being called when you inject the webcomponent javascript file with a script tag where the defer attribute is used. You can see the code here: https://codesandbox.io/s/web-component-with-setter-1ij4o

Within the script tag of the index.html, I set the property foobar to "test". This should trigger the setter of the webcomponent, which should print the value "test" to the screen by an alert command. But this does not happen. If you delete the defer attribute, everything works as expected. Can you tell me why this is happening, and do you have a solution where the setter is being called without deleting the defer attribute?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What's happening is that your inline script is running before the deferred script.

You can solve this by either putting your inline script in a file and loading it with the defer attribute OR by putting the inline code inside an event listener to run after the 'DOMContentLoaded' event.

document.addEventListener('DOMContentLoaded', () => {
  const wc = document.querySelector("custom-text");
  wc.foobar = "test";
});
about 4 years ago · Juan Pablo Isaza Relatório
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