diff options
| author | Larvan2 <[email protected]> | 2025-12-14 14:11:43 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-14 14:11:43 +0800 |
| commit | 4abe041d6d21dbd51b3093645573e8590fdcb4bb (patch) | |
| tree | bb8f2d7fccdf671d68917ae0dfddfccdb78e49ba /src/components | |
| parent | 02c5187cc003363a48a0c3dfa9c9101112d198c7 (diff) | |
| parent | 314e68812f7890e84503b1593902e8624e6b6824 (diff) | |
Merge pull request #98 from pupboss/master
fix: avoid errors in browser console
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/APIConfig.tsx | 12 | ||||
| -rw-r--r-- | src/components/Connections.tsx | 7 | ||||
| -rw-r--r-- | src/components/TrafficNow.tsx | 2 |
3 files changed, 12 insertions, 9 deletions
diff --git a/src/components/APIConfig.tsx b/src/components/APIConfig.tsx index 9491d2f..c67a157 100644 --- a/src/components/APIConfig.tsx +++ b/src/components/APIConfig.tsx @@ -86,11 +86,13 @@ function APIConfig({ dispatch }) { const detectApiServer = async () => { // if there is already a clash API server at `/`, just use it as default value const res = await fetch('/'); - res.json().then((data) => { - if (data['hello'] === 'clash') { - setBaseURL(window.location.origin); - } - }); + if (res.headers.get('content-type')?.includes('application/json')) { + res.json().then((data) => { + if (data['hello'] === 'clash') { + setBaseURL(window.location.origin); + } + }); + } }; useEffect(() => { detectApiServer(); diff --git a/src/components/Connections.tsx b/src/components/Connections.tsx index cff9a26..b76af79 100644 --- a/src/components/Connections.tsx +++ b/src/components/Connections.tsx @@ -313,9 +313,10 @@ function Conn({ apiConfig }) { ({ connections }) => { const prevConnsKv = arrayToIdKv(prevConnsRef.current); const now = Date.now(); - const x = connections.map((c: ConnectionItem) => - formatConnectionDataItem(c, prevConnsKv, now, sourceMap) - ); + const x = + connections?.map((c: ConnectionItem) => + formatConnectionDataItem(c, prevConnsKv, now, sourceMap) + ) ?? []; const closed = []; for (const c of prevConnsRef.current) { const idx = x.findIndex((conn: ConnectionItem) => conn.id === c.id); diff --git a/src/components/TrafficNow.tsx b/src/components/TrafficNow.tsx index ae69910..ad7d910 100644 --- a/src/components/TrafficNow.tsx +++ b/src/components/TrafficNow.tsx @@ -74,7 +74,7 @@ function useConnection(apiConfig) { setState({ upTotal: prettyBytes(uploadTotal), dlTotal: prettyBytes(downloadTotal), - connNumber: connections.length, + connNumber: connections ? connections.length : 0, mUsage: prettyBytes(memory), }); }, |
