-
-
Notifications
You must be signed in to change notification settings - Fork 756
Open
Labels
enhancementNew feature or request.New feature or request.
Description
What is the feature you are proposing?
Right now, implementing websockets with Bun and Hono feels like a real downgrade (see #3230 as well).
As @manastunga787 rightfully pointed out in that thread, the Bun websocket object is still available under ws.raw
but:
- This is typed as optional. I'm not sure why, but of course it means peppering null checks wherever it's being used
- More importantly, the
data
attribute is being leveraged for internal use leading to unexpected errorsonClose
:
// ....
return {
onOpen: (event, ws) => {
const { raw } = ws;
if (!raw) {
// is there a chance for this to ever be the case?
return;
}
// this leads to
// TypeError: undefined is not an object (evaluating 'websocketListeners.onClose')
// because the data initially attached is being overwritten
raw.data = {
foo: "bar",
};
},
// ...
};
I'm now copying the previously attached data as well and everything seems to work fine, but it was rather painful to debug.
I'm wondering if data
could be monkey-patched such that Hono specific data is not stored alongside application specific data.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request.New feature or request.