Skip to content

The "onClose" handler is not triggered if the component using "useWs" unmounts #400

Description

@Yovach

Hi,
I just encountered an issue while using your "useWs" implementation.
If a component using "useWs" hook unmount, the "onClose" handler is not called.

This is due to the following cleanup code : https://github.com/cloudflare/partykit/blob/main/packages/partysocket/src/use-handlers.ts#L35-L40

The event "close" event is no longer listened to, so if the websocket is closed due to an unmount, the "onClose" handler is never called. The only current solution to this problem is to create a custom cleanup function on unmount which is not ideal as the hook "useWs" already provides one.

Here is a minimal reproduction :
https://github.com/Yovach/partykit-bug-reproduction-unmount-close

Thanks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions