fix: connections is null

This commit is contained in:
GyDi 2023-06-30 09:02:17 +08:00
parent f032228d0e
commit aba0826c38
No known key found for this signature in database
GPG Key ID: 9C3AD40F1F99880A

View File

@ -56,15 +56,16 @@ const ConnectionsPage = () => {
const { connect, disconnect } = useWebsocket(
(event) => {
// meta v1.15.0 出现data.connections为null的情况
const data = JSON.parse(event.data) as IConnections;
// 尽量与前一次connections的展示顺序保持一致
setConnData((old) => {
const oldConn = old.connections;
const maxLen = data.connections.length;
const maxLen = data.connections?.length;
const connections: typeof oldConn = [];
const rest = data.connections.filter((each) => {
const rest = data.connections?.filter((each) => {
const index = oldConn.findIndex((o) => o.id === each.id);
if (index >= 0 && index < maxLen) {