Skip to content

Possible fix for webpackHotDevClient disconnecting from server. #8091

Open
@gamedev8

Description

@gamedev8

Hello I would like to submit a fix for the issue people are having with the websocket in webpackHotDevClient.js disconnecting from the server. The websocket is timing out after some time, so we simply ping the server periodically to prevent it from timing out. Here is the code I've been using.

// Ping the server to prevent the client from disconnecting
var ping = function() {
  if (connection && (connection.readyState === connection.OPEN)) {
    connection.send("ping");
    setTimeout(ping, 3000);
  }
};

connection.onopen = function() {
  if (typeof console !== 'undefined' && typeof console.info === 'function') {
    console.info(
      'The development server has connected.'
    );
  }

  ping();
};

I have a branch ready here. I can submit a PR.
https://github.com/vibelife/create-react-app/blob/master/packages/react-dev-utils/webpackHotDevClient.js#L85

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions