Code Monkey home page Code Monkey logo

Comments (6)

hugows avatar hugows commented on August 19, 2024 4

I was calling close like this:

websocket.close({ keepClosed: true });

I feel very ashamed now, re-reading the docs.

from reconnecting-websocket.

LKNSI avatar LKNSI commented on August 19, 2024 3

Yes can confirm when calling it inside of React, inside of a Vanilla Class...

...
constructor(){
   this.ws = null
}

init(){
  this.ws = new ReconnectingWebSocket('ws://...',[],{startClosed: true})
}
...

will cause two connections to be opened. Unaware if this is down to react's development strict mode, or a bug with reconnecting-websocket.

But most likely strict mode:

Strict mode can’t automatically detect side effects for you, but it can help you spot them by making them a little more deterministic. This is done by intentionally double-invoking the following functions:

Class component constructor, render, and shouldComponentUpdate methods
Class component static getDerivedStateFromProps method
Function component bodies
State updater functions (the first argument to setState)
Functions passed to useState, useMemo, or useReducer

from reconnecting-websocket.

pladaria avatar pladaria commented on August 19, 2024 1

It would be great to have some consistent steps to reproduce. Please, update the ticket if you gather more information.

Aso, additional details about your environment would be appreciated. Is this running in browser? Happens for all vendors / versions? Is the uniqueToken() always returning different tokens in every call? Are you sure that the constructor isn't called multiple times?

from reconnecting-websocket.

hugows avatar hugows commented on August 19, 2024

Hi @Joris-van-der-Wel , did you solve this?
I have something similar and not sure if its the library or my use with Redux. I'm trying now to use a unique ID so I can keep a single websocket on the server side..

from reconnecting-websocket.

ngugcx avatar ngugcx commented on August 19, 2024

I'm using this module with react. If init websocket in the constructor, it will connect twice.

class TokenWatch extends Component {
  constructor(props) {
    super(props);
    // this.ws = new ReconnectingWebSocket(URL) // will have two sockets if init here
  }

  componentDidMount() {
    this.ws = new ReconnectingWebSocket(URL) // only one socket if init here
  }
}

from reconnecting-websocket.

C5H8NNaO4 avatar C5H8NNaO4 commented on August 19, 2024

I'm having this issue as well. It doesn't seem to happen with a production build; But there are two seperate socket connections even though the constructor is only being called once.

from reconnecting-websocket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.