Skip to content

useEventSource | Add autoClose option (as in useWebSocket) #4587

@oxcabe

Description

@oxcabe

Clear and concise description of the problem

Provide an autoClose option that closes the EventSource automatically on a beforeunload window event trigger. Same thing useWebSocket provides:

/**
* Automatically close a connection
*
* @default true
*/
autoClose?: boolean

if (autoClose) {
if (isClient)
useEventListener('beforeunload', () => close(), { passive: true })
tryOnScopeDispose(close)
}

Suggested solution

Same implementation as in useWebSocket.

Alternative

N/A

Additional context

https://vueuse.org/core/useEventSource/
https://vueuse.org/core/useWebSocket/
https://vueuse.org/core/useWebSocket/#autoclose

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions