mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 16:01:42 +00:00
fix(frontend): destroy old WebsocketProvider on workspace switch in MultiplayerMenu (#9719)
Switching workspaces created a new WebsocketProvider without destroying the old one. The leaked provider kept reconnecting, causing alternating websocket traffic between old and new workspace rooms and flickering in the Live Activity sidebar. Add a disconnectWorkspace() cleanup that destroys the provider and resets connected/awareness state, call it at the start of connectWorkspace() before creating a new provider (matching ScriptEditor.svelte), and run it from an onDestroy hook so the provider is torn down on unmount. Fixes WIN-2086 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
import { onDestroy } from 'svelte'
|
||||
|
||||
import { enterpriseLicense, userStore, workspaceStore, awarenessStore } from '$lib/stores'
|
||||
|
||||
@@ -23,7 +24,17 @@
|
||||
url: $page.url.pathname
|
||||
})
|
||||
}
|
||||
function disconnectWorkspace() {
|
||||
if (wsProvider) {
|
||||
wsProvider.destroy()
|
||||
wsProvider = undefined
|
||||
}
|
||||
connected = false
|
||||
awareness = undefined
|
||||
}
|
||||
async function connectWorkspace(workspace: string) {
|
||||
disconnectWorkspace()
|
||||
|
||||
let token: string | undefined
|
||||
try {
|
||||
token = await signMultiplayerRequest(workspace)
|
||||
@@ -73,6 +84,10 @@
|
||||
$enterpriseLicense && $workspaceStore && connectWorkspace($workspaceStore)
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
disconnectWorkspace()
|
||||
})
|
||||
|
||||
let peers = $derived(
|
||||
Object.entries($awarenessStore ?? {}).filter(
|
||||
([user]) => user && user !== 'undefined' && user !== 'null'
|
||||
|
||||
Reference in New Issue
Block a user