Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
这个PR主要优化了系统配置(SystemConfig)的监听机制,并解决了Service Worker中i18n初始化时序问题。
主要变更:
- 使用EventEmitter替代MessageQueue实现SystemConfig配置变更监听,提高性能并简化代码
- 新增Promise机制确保i18n初始化完成后再访问localePath,避免Service Worker中的竞态条件
- 简化了Setting页面的状态管理代码,移除了复杂的自动刷新逻辑
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/pkg/config/config.ts |
引入EventEmitter实现配置监听,新增watch方法支持立即执行回调 |
src/locales/locales.ts |
新增initLocalesPromise确保初始化完成,新增watchLanguageChange函数监听语言变更 |
src/app/service/service_worker/script.ts |
使用watchLanguageChange动态更新脚本安装规则的locale路径 |
src/app/service/service_worker/runtime.ts |
等待initLocalesPromise后再打开文档页面 |
src/app/service/service_worker/index.ts |
使用watch方法简化云同步监听,使用Promise确保locale初始化 |
src/pages/store/AppContext.tsx |
移除SystemConfigChange监听,简化代码 |
src/pages/options/routes/utils.tsx |
useSystemConfig hook中添加useEffect监听配置变更 |
src/pages/options/routes/Setting.tsx |
移除手动配置同步逻辑,依赖useSystemConfig自动更新 |
src/pages/components/layout/Sider.tsx |
修正用户指南文档链接路径 |
src/manifest.json |
版本升级至1.3.0.1100 |
package.json |
版本升级至1.3.0-beta |
src/pkg/config/config.ts
Outdated
Comment on lines
98
to
107
| watch<T extends SystemConfigKey>(key: T, callback: (value: SystemConfigValueType<T>) => void) { | ||
| // 立即执行一次 | ||
| this.get(key).then((val) => { | ||
| callback(val); | ||
| }); | ||
| // 监听变更 | ||
| return this.addListener(key, (val) => { | ||
| callback(val); | ||
| }); | ||
| } |
There was a problem hiding this comment.
watch方法存在错误处理缺失。如果get(key)的Promise被reject,callback不会被调用,但监听器仍会被注册,导致不一致的状态。建议添加.catch()处理或使用Promise.resolve().then()包裹以确保监听器总是被注册。
| return systemConfig.addListener(key, (val) => { | ||
| setValue(val); | ||
| }); | ||
| }, [key]); |
There was a problem hiding this comment.
useEffect的依赖数组中缺少setValue。虽然setValue是由useState返回的稳定引用,但为了代码的完整性和遵循React Hooks最佳实践,建议将setValue添加到依赖数组中,或使用函数式更新形式避免依赖。
Suggested change
| }, [key]); | |
| }, [key, setValue]); |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Collaborator
|
不打算借此改一下吗 改做以下格式 如果是第一次,previous 是 undefined 例如 |
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.
概述 Descriptions
close #972
变更内容 Changes
截图 Screenshots