Skip to content

Multiple heartbeats when using share: true #268

Description

@sgrund14

Hello,

I have a situation where I'm making two calls to useWebSocket: once in the root of a remix application, and another time further down the component tree

I am using the share: true option in both cases, and both have the same URL

// root.tsx

const Root() {
   useWebSocket<MessageResponseType>(
    'wss://example.com'
    {
      ...otherOptions
      heartbeat: {
        message: JSON.stringify({ message: 'keep-alive' }),
        interval: 60,
        timeout: 120
      },
      share: true,
    },
  return <ChildrenComponents />
}


// children.tsx

const ChildrenComponents() {
   useWebSocket<MessageResponseType>(
    'wss://example.com'
    {
      ...otherOptions,
      share: true,
    },
}

The problem here is, even though the child component is not passing the heartbeat option and the root component is, I am not seeing a heartbeat message

But then if I pass a heartbeat option the the child component, like so

// children.tsx

const ChildrenComponents() {
   useWebSocket<MessageResponseType>(
    'wss://example.com'
    {
      ...otherOptions,
      heartbeat: {
        message: JSON.stringify({ message: 'keep-alive' }),
        interval: 60,
        timeout: 120
      },
      share: true,
    },
}

Then I start to get two heartbeat messages. Ideally I would just be getting one heartbeat, and be able to share the connection

Any thoughts?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions