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

206
Visualizações
WebSocket gets disconnected after upgrade to react18

I've noticed something interesting after I've upgraded my react project from version 17.0.2 to version 18.0.0.

On the homepage of my application I'm opening a connection for a WebSocket using SignalR. Everything is running fine with React 17.0.2, but after the upgrade to React 18.0.0, for some reason the WebSocket keeps getting disconnected. After that, I switched back to React 17.0.2 and the issues was fixed.

I'm not really sure why and I couldn't find any questions related to this topic.

The only thing that I did was to update my package.json to use version 18 of react and react-dom and after that in index.js I've made the necessary changes.

If anyone has a similar issues after upgrading to React 18, some informations would be helpful.

Thanks and in the meantime I'll do some more research, maybe I can find out what is the problem.

UPDATE The problem seems to be related to <React.StrictMode> that wraps my entire application's code.

For some reason, when using strict mode, react triggers the useEffect cleanup function that is disconnecting the WebSocket from the HomePage once you leave that page. I've removed the strict mode and now it works fine (this is only available for react 18, if I keep using react 17 with strict mode, I don't have this "issue")

More info here about how React.StrictMode works: https://github.com/reactwg/react-18/discussions/19

about 4 years ago · Santiago Trujillo
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