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

Vite 6 Breaks server.ws.clients APIs #18781

Open
antfu opened this issue Nov 26, 2024 · 0 comments
Open

Vite 6 Breaks server.ws.clients APIs #18781

antfu opened this issue Nov 26, 2024 · 0 comments
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) regression The issue only appears after a new release

Comments

@antfu
Copy link
Member

antfu commented Nov 26, 2024

Describe the bug

This is introduced by #18362

The server.ws.clients is refactored to be a superset of HotChannelClient which expect a simple send(payload) function, but previously server.ws.clients we also support the send(event, data) signature.

In vite-dev-rpc, the usage is like this:

https://github.com/antfu/vite-dev-rpc/blob/b6899623ed19297e5927262396f0d4bfdc34016b/src/index.ts#L17-L32

There are two problems,

  1. At L27 of the pointed file, server.ws.clients#send does not support send(event, data) signature, which is addressed by fix(server): recover server.ws.clients.send API changes for back compatibility #18779
  2. At L22, we check if the event is coming from a certain client to filter out, but due to the normalization made in feat: use a single transport for fetchModule and HMR support #18362, the second argument of the callback no longer returns the same instance, while the .socket from WebSocketClient also get lost. By (
    const listenerWithNormalizedClient = (
    data: any,
    client: HotChannelClient,
    ) => {
    const normalizedClient: NormalizedHotChannelClient = {
    send: (...args) => {
    let payload: HotPayload
    if (typeof args[0] === 'string') {
    payload = {
    type: 'custom',
    event: args[0],
    data: args[1],
    }
    } else {
    payload = args[0]
    }
    client.send(payload)
    },
    }
    fn(data, normalizedClient)
    }
    normalizedListenerMap.set(fn, listenerWithNormalizedClient)

I am not sure if we should do specially handling for WebSocketServer, or should we also consider that the more general cases:

Due to the normalization made to the client:

  1. The NormalizedHotChannelClient only exposes the send function, where the HotChannelClient is actually an interface that users or other integrations might put more attributes or data in the client (in this case, WebSocketClient has a .socket prop)
  2. Lose the ability to track the client instances. The second argument of the callback should also be able to identify which client is calling it. If we get (1) supported, users could put an id or any other field to help identifying, while the instance check might still not working (if we consider it strictly, it might still be a breaking change)?

Raised this issue to discuss with design direction we should go to get back the compatibility or capability.

Reproduction

https://github.com/antfu/vite-dev-rpc

Steps to reproduce

Upgrade Vite to 6.0.0 and run pnpm run dev, it should show a A + B = C that calculated on server side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) regression The issue only appears after a new release
Projects
None yet
Development

No branches or pull requests

1 participant