Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not use webSocketURL #742

Open
ChocolateLoverRaj opened this issue Mar 28, 2023 · 6 comments · May be fixed by #851
Open

Does not use webSocketURL #742

ChocolateLoverRaj opened this issue Mar 28, 2023 · 6 comments · May be fixed by #851

Comments

@ChocolateLoverRaj
Copy link

Here is the docs for the option: https://webpack.js.org/configuration/dev-server/#websocketurl
This plugin just sends a request to /ws, even if a different path, hostname, or port is specified.
Link to reproduce: https://github.com/ChocolateLoverRaj/webpack-dev-server-bug/tree/react-refresh#readme

@pmmmwh
Copy link
Owner

pmmmwh commented Apr 12, 2023

Support for this option have not been added, but should be. I'll try to find time to work on this.

@Codex101
Copy link

Codex101 commented May 1, 2023

I'm pretty sure this is why I keep getting an error with websocket connection failure. Despite setting the react refresh overlay websockets. setting the dev-server host and the client websocket url details.

websocket connection to 'ws://localhost/ws' failed: Error during Websocket handshake: Unspected response code: 404
[webpack-dev-server] (error message)
[webpack-dev-server] Trying to reconnect... 

Constantly repeats

@Codex101
Copy link

@pmmmwh Do you know where the plugin sends a the websocket connection request to webpack-dev-server, using the default /ws url? Trying to suppress this error on local. I cannot find where the ws requests get sent off.

@ChocolateLoverRaj
Copy link
Author

ChocolateLoverRaj commented May 24, 2023

@pmmmwh Do you know where the plugin sends a the websocket connection request to webpack-dev-server, using the default /ws url? Trying to suppress this error on local. I cannot find where the ws requests get sent off.

I did a text search on GitHub for "ws" and I found this:

I'm not sure if this code needs to be changed

@Codex101
Copy link

Codex101 commented May 24, 2023

//@ChocolateLoverRaj The urlParts.pathname actually does pick up the webpack websocketUrl config value.

eg, hardcoding the urlParts.pathname into my desired format doesn't work.

  if (!urlParts.pathname) {
    if (metadata.version === 4) {
      // This is hard-coded in WDS v4
      urlParts.pathname = 'dist/ws';
    } else {
      // This is hard-coded in WDS v3
      urlParts.pathname = '/sockjs-node';
    }
  }

It's very weird, in WDSSocket.js does create a connection with the correct websocketUrl value from webpack, ws://localhost:1212/dist/ws. However, the react refresh plugin just sends websocket connection requests to 'ws://localhost/ws`, same error my first comment.

@pmmmwh
Copy link
Owner

pmmmwh commented Aug 9, 2023

/ws is actually hardcoded in webpack-dev-server. We should try migrating to their newer API where the dev server can be imported and used directly ... but fixing this fallback of constructing the socket client could be valuable as well.

@Codex101 perhaps you need to set the port properly?

@pmmmwh pmmmwh linked a pull request Jun 2, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants