From 1392410fa9f157ff52856fadcfa61ef83f5a5382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Fern=C3=A1ndez?= Date: Sun, 29 Jan 2023 02:13:59 +0100 Subject: [PATCH] feat(useWebSocket): allow undefined ref for url (#2473) * feat(useWebSocket): allow undefined ref for url * docs(useWebSocket): update outdated type declarations --- packages/core/useWebSocket/index.md | 2 +- packages/core/useWebSocket/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/useWebSocket/index.md b/packages/core/useWebSocket/index.md index fa6e16fc70b..3979c5bc761 100644 --- a/packages/core/useWebSocket/index.md +++ b/packages/core/useWebSocket/index.md @@ -174,7 +174,7 @@ export interface WebSocketResult { * @param url */ export declare function useWebSocket( - url: string, + url: MaybeComputedRef, options?: WebSocketOptions ): WebSocketResult ``` diff --git a/packages/core/useWebSocket/index.ts b/packages/core/useWebSocket/index.ts index e67fcb566d7..32b958c2d5c 100644 --- a/packages/core/useWebSocket/index.ts +++ b/packages/core/useWebSocket/index.ts @@ -143,7 +143,7 @@ function resolveNestedOptions(options: T | true): T { * @param url */ export function useWebSocket( - url: MaybeComputedRef, + url: MaybeComputedRef, options: UseWebSocketOptions = {}, ): UseWebSocketReturn { const { @@ -205,7 +205,7 @@ export function useWebSocket( } const _init = () => { - if (explicitlyClosed) + if (explicitlyClosed || typeof urlRef.value === 'undefined') return const ws = new WebSocket(urlRef.value, protocols)