Summary
useWebSocket in packages/data/src/hooks.ts reconnects when url changes, but it never clears the message state. Consumers can see the previous socket's last message while the new socket is still connecting.
Reproduction
- Render useWebSocket('wss://old.example').
- Receive a message such as old-data.
- Re-render with useWebSocket('wss://new.example').
- Inspect message before the new socket receives anything.
Expected behavior
A URL change should reset message to
ull or otherwise make it clear that the old message belongs to the old connection.
Actual behavior
The hook keeps returning the old message while state is already for the new connection lifecycle.
Summary
useWebSocket in packages/data/src/hooks.ts reconnects when url changes, but it never clears the message state. Consumers can see the previous socket's last message while the new socket is still connecting.
Reproduction
Expected behavior
A URL change should reset message to
ull or otherwise make it clear that the old message belongs to the old connection.
Actual behavior
The hook keeps returning the old message while state is already for the new connection lifecycle.