Repository navigation
Stabilize ChatView and App callbacks to stop closure chains - #150
Merged
shaohaozhi286 merged 1 commit intoOct 19, 2026
Merged
Conversation
Session switches and status updates rebuilt ChatView/App callbacks with different dependencies on alternating renders, so V8 kept every render's scope alive through the shared closure context. Callbacks that depend on changing state or props now use useStableCallback (ChatView 100, App 34). - Keep useCallback where identity must follow the session: ChatView's async submit path calls draft/history/send/upload/preview helpers after an await, and ChatView does not remount per session (10 kept, reasons recorded in the test). App keeps the two functions handed to hooks. - Effects that relied on callback identity to rerun now list the values they follow (focus, queue drain, tail-follow, change dock, browser tab restore, preview auto-refresh). - Replace the Sidebar-only guard with stableCallbacksArchitecture.test.js covering Sidebar, ChatView and App; update source-anchor tests. Measured with an isolated daemon and headless Edge (160 alternating session switches / unread toggles): ChatView scopes retained 262 -> 17, App 176 -> none.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
#148 修掉了 Desktop 挂机 OOM 的主因(侧栏空闲渲染 + 闭包链)。之后实测发现,活跃使用(切换会话 + 状态变化)时 ChatView 与 App 仍在接链:依赖各不相同的
useCallback在不同渲染里交替重建,V8 让同一次渲染的闭包共享一个作用域,旧回调把整份渲染作用域留住。改动
useStableCallback。useCallback的回调(测试里的KEEP表逐条写明原因):submit等异步流程在await之后调用的会话绑定回调(草稿、输入历史、发送、上传、回填输入框、打开预览)共 10 个。若改成稳定引用,用户中途切会话时会作用到新会话上。usePreviewPresentation/useRef的两个函数(渲染期间调用)。stableCallbacksArchitecture.test.js,覆盖 Sidebar / ChatView / App;源码锚点类测试同步更新。验证
pnpm test全量 3261 条通过,pnpm build通过。