From c055b4d32dbe719134228f13cb711ce5d11d5525 Mon Sep 17 00:00:00 2001
From: syuilo <syuilotan@yahoo.co.jp>
Date: Sun, 1 Nov 2020 11:57:34 +0900
Subject: [PATCH] =?UTF-8?q?fix(client):=20=E3=82=B9=E3=83=88=E3=83=AA?=
 =?UTF-8?q?=E3=83=BC=E3=83=9F=E3=83=B3=E3=82=B0=E3=81=AE=E3=83=A1=E3=83=A2?=
 =?UTF-8?q?=E3=83=AA=E3=83=AA=E3=83=BC=E3=82=AF=E3=82=92=E4=BF=AE=E6=AD=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

SharedConnection や NonSharedConnection のインスタンスを Vue コンポーネントの data に含むと、Vue が Proxy に変換するため、Stream クラス内部でインスタンス同士の比較をしても false になり、使われなくなったインスタンスがメモリ上に残り続ける。
なお、チャンネルへの接続/切断は頻繁に行うものではないため、メモリリークといっても影響は軽微とみられる。
---
 src/client/scripts/stream.ts | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/client/scripts/stream.ts b/src/client/scripts/stream.ts
index 942e2a8daa..7330a2f8bb 100644
--- a/src/client/scripts/stream.ts
+++ b/src/client/scripts/stream.ts
@@ -1,6 +1,7 @@
 import autobind from 'autobind-decorator';
 import { EventEmitter } from 'eventemitter3';
 import ReconnectingWebsocket from 'reconnecting-websocket';
+import { markRaw } from 'vue';
 import { debug, wsUrl } from '@/config';
 import { query as urlQuery } from '../../prelude/url';
 
@@ -36,7 +37,7 @@ export default class Stream extends EventEmitter {
 			this.sharedConnectionPools.push(pool);
 		}
 
-		const connection = new SharedConnection(this, channel, pool, name);
+		const connection = markRaw(new SharedConnection(this, channel, pool, name));
 		this.sharedConnections.push(connection);
 		return connection;
 	}
@@ -53,7 +54,7 @@ export default class Stream extends EventEmitter {
 
 	@autobind
 	public connectToChannel(channel: string, params?: any): NonSharedConnection {
-		const connection = new NonSharedConnection(this, channel, params);
+		const connection = markRaw(new NonSharedConnection(this, channel, params));
 		this.nonSharedConnections.push(connection);
 		return connection;
 	}