Skip to content

refactor(app): extract event listener / sync toast hooks and tighten ref typing#3786

Open
RainyNight9 wants to merge 2 commits into
farion1231:mainfrom
K-H-N-L:refactor/app-struct-typing
Open

refactor(app): extract event listener / sync toast hooks and tighten ref typing#3786
RainyNight9 wants to merge 2 commits into
farion1231:mainfrom
K-H-N-L:refactor/app-struct-typing

Conversation

@RainyNight9
Copy link
Copy Markdown

Summary / 概述

背景

App.tsx 承担了过多职责(事件订阅/卸载、toast 通用化、ref 强类型),本 PR 仅做结构与类型收敛,不改变任何运行时行为。后续想帮忙继续优化一下前端代码。

变更(2 个 commit)

1. chore(pnpm): allow esbuild and msw in onlyBuiltDependencies

  • pnpm 10+ 默认阻止依赖的安装期脚本,但 esbuild(Vite 工具链)和 msw(Vitest 测试 mock)需要运行 install/postinstall 步骤来准备平台二进制。
  • pnpm-workspace.yamlonlyBuiltDependencies 中追加 esbuildmsw,仅解除 pnpm 对这两个包的脚本拦截。

2. refactor(app): 抽出事件订阅与 auto-sync toast 通用 hook,并收紧 ref 类型

  • 新增 useProviderSwitchListener(activeApp, onRefetch),统一管理 providersApi.onSwitched 订阅与卸载,替代 App 内的内联 useEffect
  • 新增 useAutoSyncErrorToast(eventName, queryClient, t, toastI18nKey),合并 WebDAV/S3 自动同步失败 toast 的重复逻辑。
  • 收紧 Panel ref 类型:PromptPanelRef / McpPanelRef / SkillsPageRef / UnifiedSkillsPanelRef 改为 useRef<...Handle | null>(null),取代此前的 useRef<any>,调用点改用可选链避免运行时空方法。
  • 不新增组件文件,限制在 App.tsx 内重构,便于评审。

兼容性

纯重构,无 API/行为变更;不引入新依赖,不修改 i18n 文案。

Related Issue / 关联 Issue

Fixes #

Screenshots / 截图

Before / 修改前 After / 修改后

Checklist / 检查清单

  • pnpm typecheck passes / 通过 TypeScript 类型检查
  • pnpm format:check passes / 通过代码格式检查
  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Updated i18n files if user-facing text changed / 如修改了用户可见文本,已更新国际化文件

pnpm 10+ 默认阻止依赖的安装期脚本,但 esbuild(Vite 工具链)和
msw(Vitest 测试 mock)需要运行 install/postinstall 步骤来准备
平台二进制,否则本地安装/测试可能异常或构建降级。

- pnpm-workspace.yaml: 在 onlyBuiltDependencies 中追加 esbuild、msw
- 行为不变;只解除 pnpm 对这两个包的脚本拦截
只做结构与类型收敛,不改变任何运行时行为:

- 新增 useProviderSwitchListener(activeApp, onRefetch)
  统一管理 providersApi.onSwitched 订阅与卸载,替代 App 内的内联 useEffect
- 新增 useAutoSyncErrorToast(eventName, queryClient, t, toastI18nKey)
  合并 WebDAV/S3 自动同步失败 toast 的重复逻辑
- 收紧 Panel ref 类型:PromptPanelRef/McpPanelRef/SkillsPageRef/
  UnifiedSkillsPanelRef 改为 useRef<...Handle | null>(null)
  取代此前的 useRef<any>,调用点改用可选链避免运行时空方法
- 不新增组件文件,限制在 App.tsx 内重构,便于评审
@RainyNight9 RainyNight9 changed the title Refactor/app struct typing refactor(app): 抽出事件订阅与 auto-sync toast 通用 hook,并收紧 ref 类型 Jun 5, 2026
@RainyNight9 RainyNight9 changed the title refactor(app): 抽出事件订阅与 auto-sync toast 通用 hook,并收紧 ref 类型 refactor(app): extract event listener / sync toast hooks and tighten ref typing Jun 5, 2026
@farion1231
Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants