Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [v1.0.12] - 2026-11-07

- perf(react): 稳定 useSyncExternalStore 订阅引用,避免每次渲染重绑 (64a77cd7)
- chore(api): 删除已无引用的手写 SSE 解析器 (3fa5d84b)
- perf(panel): 右侧面板首次打开前不再挂载 files/changes 内容 (a9c7d271)
- perf(sidebar): 不再为最近会话的每个目录打开 shell 库存 (f8e8a2c0)
- fix(permission): 旧快照不再复活已经通过的权限请求 (b6847a1c)
- fix(desktop): 刷新后复用本机服务,不再重走完整启动流程 (97d24b5e)
- perf(session-list): 目录补拉批量合并,重连时强制补偿首屏 (6b6b1411)
- perf(server): 健康检查与探测降噪,快照引用稳定,SSE 状态与健康收敛 (d5fc1067)
- perf(events): 全局状态接口只查一次,目录引用抖动不再触发刷新风暴 (0da0c9e2)
- perf(api): 桌面端首请求固定走 Tauri fetch,避免 CORS 必败重试 (ff5491ef)

## [v1.0.11] - 2026-11-02

- fix(markdown): 长公式支持横向滚动 (44800bdd)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opencodeui",
"version": "1.0.11",
"version": "1.0.12",
"description": "A third-party web frontend for OpenCode",
"license": "GPL-3.0-only",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opencodeui"
version = "1.0.11"
version = "1.0.12"
description = "OpenCode UI - Tauri Mobile App"
authors = ["lehhair"]
license = "GPL-3.0-only"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "OpenCode",
"version": "1.0.11",
"version": "1.0.12",
"identifier": "com.opencodeui.app",
"build": {
"frontendDist": "../dist",
Expand Down
27 changes: 23 additions & 4 deletions src/api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,40 @@ function getOrCreateConnection(serverId: string): ServerConnection {
function updateConnectionState(serverId: string, update: Partial<ConnectionInfo>): void {
const conn = connections.get(serverId)
if (!conn) return
const becameConnected = update.state === 'connected' && conn.info.state !== 'connected'
conn.info = { ...conn.info, ...update }
// 设置页的健康灯和侧边栏的 SSE 状态必须收敛:连上了就把健康快照提升为
// 在线,否则启动期失败的探测结果会一直红着(健康轮询已跳过已连接服务器)
if (becameConnected) serverStore.noteServerConnected(serverId)
connectionListeners.get(serverId)?.forEach(fn => {
fn(conn.info)
})
}

/**
* 逐个通知订阅者;单个订阅者抛错不能中断其余订阅者。
*
* 重连补偿 / server.connected 这类通知后面挂着「重新拉取状态、补消息」,
* 一个 pane 的回调炸掉会让后面的 pane 全部错过补偿,表现为部分界面一直
* 停在断线前的状态。
*/
function notifySubscribers(conn: ServerConnection, invoke: (callbacks: EventCallbacks) => void): void {
conn.subscribers.forEach(callbacks => {
try {
invoke(callbacks)
} catch (error) {
callbacks.onError?.(error instanceof Error ? error : new Error(String(error)))
}
})
}

function broadcastReconnected(conn: ServerConnection, reason: 'network' | 'server-switch'): void {
const now = Date.now()
if (reason !== 'server-switch' && now - conn.lastReconnectedBroadcast < RECONNECTED_COOLDOWN) {
return
}
conn.lastReconnectedBroadcast = now
conn.subscribers.forEach(cb => {
cb.onReconnected?.(reason)
})
notifySubscribers(conn, callbacks => callbacks.onReconnected?.(reason))
}

function getReconnectDelay(attempt: number): number {
Expand Down Expand Up @@ -631,7 +650,7 @@ async function connectServer(serverId: string): Promise<void> {
// 通知只在**这一处**发:之前上面那个分支里也发过一次,导致首次连接时
// 每个订阅者被触发两遍。
if (event.type === 'server.connected') {
conn.subscribers.forEach(cb => cb.onServerConnected?.())
notifySubscribers(conn, callbacks => callbacks.onServerConnected?.())
continue
}

Expand Down
3 changes: 3 additions & 0 deletions src/api/sdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ describe('v2 client request lifecycle', () => {
})

const request = client.__fetch('http://127.0.0.1:4096/api/session')
// 注入的 fetch 现在会先 await 传输实现(Tauri 下是 plugin-http 的
// 动态 import),所以等它真正起飞后再中断,覆盖「在途请求被 abort」路径。
await vi.waitFor(() => expect(signal).toBeDefined())

abortInFlightApiRequests('Server endpoint changed')

Expand Down
29 changes: 26 additions & 3 deletions src/api/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,21 @@ async function getTauriFetch(): Promise<typeof globalThis.fetch> {
return _tauriFetchLoading
}

function getFetchImpl(): typeof globalThis.fetch {
return isTauri() && _tauriFetch ? _tauriFetch : globalThis.fetch
/**
* 解析本次请求实际使用的 fetch 实现。
*
* 桌面端必须用 Tauri 的 plugin-http:webview 里的原生 fetch 受 CORS 约束,
* 而 opencode serve 默认不带 `--cors`,从 tauri:// 源打到 127.0.0.1 的首个
* 请求会被浏览器直接拒绝。之前这里是「tauri fetch 已加载就用,否则用原生」,
* 启动时请求只要比动态 import 先到,就会白打一次必败请求并进入重试退避——
* 首屏会话/模型列表因此慢半拍甚至停在失败态。
*
* 现在改成等 import 落地(本身被缓存,之后是已 resolve 的 promise),
* 保证第一次请求就走对通道。
*/
async function resolveFetchImpl(): Promise<typeof globalThis.fetch> {
if (!isTauri()) return globalThis.fetch
return await getTauriFetch()
}

function createAbortError(message: string) {
Expand Down Expand Up @@ -99,7 +112,17 @@ async function trackedFetch(
throw createAbortError('Stale API request')
}

const fetchPromise = getFetchImpl()(input, {
const fetchImpl = await resolveFetchImpl()
// 等待 import 期间可能又发生了端点切换:起飞前再校验一次代次
if (generation !== _apiRequestGeneration) {
throw createAbortError('Stale API request')
}
// 等待期间外部取消(切会话 / 断连)也要在起飞前生效
if (controller.signal.aborted) {
throw controller.signal.reason ?? createAbortError('Request aborted')
}

const fetchPromise = fetchImpl(input, {
...init,
signal: controller.signal,
})
Expand Down
19 changes: 0 additions & 19 deletions src/api/sse.test.ts

This file was deleted.

36 changes: 0 additions & 36 deletions src/api/sse.ts

This file was deleted.

22 changes: 21 additions & 1 deletion src/components/RightPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function PanelFallback() {
)
}

/** 面板未打开过时的占位渲染器(稳定引用,避免每次渲染换新函数) */
const renderNothing = () => null

interface RightPanelProps {
terminals: SessionTerminals
directory?: string
Expand All @@ -52,6 +55,21 @@ export const RightPanel = memo(function RightPanel({
const { interaction, layout } = useChatViewport()
const normalizedDirectory = directory ? normalizeToForwardSlash(directory) : undefined

/**
* 桌面端右侧面板关闭时不再挂载内容。
*
* 面板关闭时 `ResizablePanel` 只是把宽度收成 0,children 仍会渲染:
* 默认 tab 是 files + changes,于是启动就拉文件树/文件状态,切会话还会
* 拉 session.diff——用户根本没打开面板。这里第一次打开后才挂载,之后
* 保持挂载(切 tab 不丢展开态和预览)。
*/
const [desktopContentMounted, setDesktopContentMounted] = useState(rightPanelOpen)
useEffect(() => {
if (!rightPanelOpen) return
// eslint-disable-next-line react-hooks/set-state-in-effect -- 一次性挂载闸门,只从 false→true
setDesktopContentMounted(true)
}, [rightPanelOpen])

// 追踪面板 resize 状态
const [isPanelResizing, setIsPanelResizing] = useState(false)
useEffect(() => {
Expand Down Expand Up @@ -163,6 +181,8 @@ export const RightPanel = memo(function RightPanel({
[normalizedDirectory, sessionId, isPanelResizing, t, serverId],
)

const renderDesktopContent = desktopContentMounted ? renderContent : renderNothing

if (inline) {
return (
<div className="flex h-full w-full flex-col overflow-hidden bg-bg-100 [contain:layout_paint]">
Expand Down Expand Up @@ -200,7 +220,7 @@ export const RightPanel = memo(function RightPanel({
{tab => (
<div className="flex h-full flex-col">
<TerminalRestoreStatus terminals={terminals} />
<div className="flex-1 min-h-0">{renderContent(tab)}</div>
<div className="flex-1 min-h-0">{renderDesktopContent(tab)}</div>
</div>
)}
</PanelContainer>
Expand Down
4 changes: 2 additions & 2 deletions src/features/chat/ChatPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import { useServerStore } from '../../hooks/useServerStore'
import { useCancelHint } from '../../hooks/useCancelHint'
import { makeSessionKey, sessionKeyToServerId, splitSessionKey } from '../../utils/sessionKey'
import { serverStore } from '../../store/serverStore'
import { serverStore, subscribeServerStore } from '../../store/serverStore'
import {
InlineToolRequestContext,
partitionUnclaimedRequests,
Expand Down Expand Up @@ -187,7 +187,7 @@

// 当前 pane 绑定的服务器(sessionId 为复合 key,split 出 serverId;home 状态跟随 active server 实时变化)
const activeServerId = useSyncExternalStore(
cb => serverStore.subscribe(cb),
subscribeServerStore,
() => serverStore.getActiveServerId(),
() => serverStore.getActiveServerId(),
)
Expand Down Expand Up @@ -446,7 +446,7 @@
// second low-priority render lane.
const deferredMessageView = useDeferredValue(shouldDeferMessages ? messageView : null)
const renderedMessagesView = shouldDeferMessages && deferredMessageView ? deferredMessageView : messageView
const renderedMessages = renderedMessagesView.sessionId === routeSessionId ? renderedMessagesView.messages : []

Check warning on line 449 in src/features/chat/ChatPane.tsx

View workflow job for this annotation

GitHub Actions / validate

The 'renderedMessages' conditional could make the dependencies of useMemo Hook (at line 455) change on every render. To fix this, wrap the initialization of 'renderedMessages' in its own useMemo() Hook
const isRenderingDeferredMessages = renderedMessages !== messages
// 队列回声投影(官方 visibleTimelineMessages 同款):
// queue 回声隐藏(由队列气泡呈现),steer 回声挪到转写末尾
Expand Down
4 changes: 2 additions & 2 deletions src/features/chat/InputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
} from './input/attachmentUpload'
import { createUploadId } from '../../api/file'
import { notificationStore } from '../../store/notificationStore'
import { LOCAL_SERVER_ID, serverStore } from '../../store/serverStore'
import { LOCAL_SERVER_ID, serverStore, subscribeServerStore } from '../../store/serverStore'
import { sessionKeyToServerId } from '../../utils/sessionKey'
import { keybindingStore, matchesKeybinding } from '../../store/keybindingStore'
import { themeStore } from '../../store/themeStore'
Expand Down Expand Up @@ -324,7 +324,7 @@ function InputBoxComponent({
* 去引用一个服务端根本读不到的宿主路径。
*/
const endpointStates = useSyncExternalStore(
serverStore.subscribe.bind(serverStore),
subscribeServerStore,
() => serverStore.getEndpointStates(),
() => serverStore.getEndpointStates(),
)
Expand Down
4 changes: 2 additions & 2 deletions src/features/chat/input/InputFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { memo, useSyncExternalStore } from 'react'
import { useTranslation } from 'react-i18next'
import type { RefObject } from 'react'
import { FastForwardIcon } from '../../../components/Icons'
import { autoApproveStore, type FullAutoMode } from '../../../store/autoApproveStore'
import { autoApproveStore, subscribeFullAutoMode, type FullAutoMode } from '../../../store/autoApproveStore'

// ============================================
// Full Auto 状态 hook
// ============================================

function useFullAutoMode(paneId: string): FullAutoMode {
return useSyncExternalStore(
cb => autoApproveStore.onFullAutoChange(cb),
subscribeFullAutoMode,
() => autoApproveStore.getPaneFullAutoMode(paneId),
)
}
Expand Down
30 changes: 18 additions & 12 deletions src/features/chat/sidebar/SidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export function SidePanel({
const busySessions = useBusySessions()
const busyCount = useBusyCount()
useSyncExternalStore(
childSessionStore.subscribe.bind(childSessionStore),
childSessionStore.subscribe,
childSessionStore.getVersion,
childSessionStore.getVersion,
)
Expand Down Expand Up @@ -336,22 +336,28 @@ export function SidePanel({
return map
}, [sessions, fetchedSessions])

// 活跃 tab 要发现「idle 但后台 shell 在跑」的会话:库存按目录隔离且只拉
// 登记过的目录,挂载行只登记自己可见的——这里把所有已知会话的目录都登记上,
// 否则那些目录的库存根本不会出现(先有鸡先有蛋)
const sessionDirectoriesKey = useMemo(() => {
// 活跃 tab 要发现「idle 但后台 shell 在跑」的会话:只给「正在跑的会话」目录
// 做一次库存水合,其余目录靠全局 shell.created/exited 事件维护。
//
// 原来这里会把最近会话索引里出现的所有目录(200 条会话可能横跨几十个项目)
// 一次性 trackDirectory:每个目录立刻 listShells,之后每 15s 再轮询全部——
// 等于冷启动就把用户没打开的工作区全开了。当前会话 / 可见会话行的目录
// 由各自组件按需登记。
const busyDirectoriesKey = useMemo(() => {
const dirs = new Set<string>()
for (const session of sessionLookup.values()) {
const dir = session.location?.directory
if (dir) dirs.add(dir)
const activeServerId = serverStore.getActiveServerId()
for (const entry of busySessions) {
// shell 库存只跟活动服务器(v1 边界),别的服务器的目录登记了也只会拉错数据
if (splitSessionKey(entry.sessionId).serverId !== activeServerId) continue
if (entry.directory) dirs.add(entry.directory)
}
return [...dirs].sort().join('\n')
}, [sessionLookup])
}, [busySessions])
useEffect(() => {
if (!sessionDirectoriesKey) return
const untracks = sessionDirectoriesKey.split('\n').map(dir => shellInventoryStore.trackDirectory(dir))
if (!busyDirectoriesKey) return
const untracks = busyDirectoriesKey.split('\n').map(dir => shellInventoryStore.trackDirectory(dir))
return () => untracks.forEach(untrack => untrack())
}, [sessionDirectoriesKey])
}, [busyDirectoriesKey])

// 后台 shell 在跑但不在 busy 名单里的会话 → 合成活跃条目(backgroundOnly)。
// 会话对象必须能从 lookup 解析(否则标题/目录都没有,挂出来也是死行)
Expand Down
Loading
Loading