Git Product home page Git Product logo

Comments (5)

njarraud avatar njarraud commented on May 25, 2024

With debugging -

Pass (abc)
Capture d’écran 2023-11-03 à 14 26 47

Fail (abcd)
Capture d’écran 2023-11-03 à 14 25 54

The only difference is engine.io-client:websocket displaying websocket closed before onclose event at then end.

Heartbeat is still working afterwards.

from socket.io-client.

njarraud avatar njarraud commented on May 25, 2024

Here is a github repo to reproduce the error https://github.com/mecabricks/debug-socketio

To Reproduce

  1. yarn dev-ws
  2. yarn dev
  3. Make a GET request to the page http://localhost:3000/api/test
  4. See the logs in the socket.io server terminal window

Current vs. Expected behavior
The socket.io server shall receive the 3 messages sent by the socket.io client (server side) however only two are received - The two with the same length. The longest is not sent over the network.

socket.emit("partLibraryIconEvent", { test: "abc" });   // OK
socket.emit("partLibraryIconEvent", { test: "abcd" });  // NOT OK
socket.emit("partLibraryIconEvent", { test: "123" });   // OK

from socket.io-client.

filipjnc avatar filipjnc commented on May 25, 2024

Experiencing the same, had to move all server code using websockets back to pages dir api routes.

I'm wondering why the websocket gets closed. Do we need to set some extra response headers on routes using websockets? Is this even a socket.io issue or a next.js issue?

from socket.io-client.

njarraud avatar njarraud commented on May 25, 2024

I believe that NextJS is overwriting something when packing the code. We cannot figure out what.
However, the solution that I just found is to exclude the socket.io-client package from webpack on the server.

Here is the code to go in next.config.js

webpack: (config, { isServer }) => {
  isServer && (config.externals = [...config.externals,  'socket.io-client']);
  return config;
},

from socket.io-client.

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.