-
Notifications
You must be signed in to change notification settings - Fork 314
[v1.3] 修复编辑器中 ESLint 修复功能失效的问题(globalCache.get("eslint-fix") 为 undefined)- 修复 #1079 #1184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/v1.3
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
该 PR 旨在修复脚本编辑器中 ESLint “Fix/Quick Fix” 在特定情况下失效(globalCache.get("eslint-fix") 为 undefined)的问题,通过将 ESLint fix 的存储从页面内的临时缓存迁移到 Monaco 的页面级全局环境(window.MonacoEnvironment)来提高稳定性,避免因缓存生命周期/重启导致的取值异常。
Changes:
- 抽离 Monaco 编辑器多语言文案到
langs.ts,并在编辑器初始化时动态更新语言。 - 重构 linter worker 为页面级单例:新增
LinterWorkerController+deferred控制 worker 初始化时序。 - 将 ESLint fix 缓存从
globalCache改为window.MonacoEnvironment.eslintFixMap,并调整相关调用方的导入/使用方式(默认导出改为具名导出)。
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pkg/utils/monaco-editor/langs.ts | 新增编辑器多语言文案与类型导出,供 Monaco hover/quickfix 使用 |
| src/pkg/utils/monaco-editor/index.ts | 重构 registerEditor 初始化流程,引入 worker 单例控制与 eslintFixMap 存储位置变更 |
| src/pages/options/main.tsx | 更新为具名导入 registerEditor |
| src/pages/install/main.tsx | 更新为具名导入 registerEditor |
| src/pages/components/CodeEditor/index.tsx | ESLint lint/marker 处理改用 LinterWorkerController,并将 fix 写入 MonacoEnvironment 的 map |
| if (eslintFixMap) { | ||
| message.markers.forEach((m: TMarker) => { | ||
| if (m.fix) { | ||
| const key = `${m.code.value}|${m.startLineNumber}|${m.endLineNumber}|${m.startColumn}|${m.endColumn}`; | ||
| eslintFixMap.set(key, m.fix); | ||
| } | ||
| }); |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里把 eslintFixMap 作为全局 Map 只做 set、不做清理,会留下已不存在 marker 的旧 fix;更关键的是当同一个 key 的 marker 之后不再提供 fix 时,旧值仍会被命中,导致 Quick Fix 显示/应用过期修复。建议每次收到 message 时先按当前 editor/model 重建(或至少先删除本次 message 未包含 fix 的 key),并考虑按 model.uri 或 editor id 做隔离,避免不同编辑器之间相互污染。
| if (eslintFixMap) { | |
| message.markers.forEach((m: TMarker) => { | |
| if (m.fix) { | |
| const key = `${m.code.value}|${m.startLineNumber}|${m.endLineNumber}|${m.startColumn}|${m.endColumn}`; | |
| eslintFixMap.set(key, m.fix); | |
| } | |
| }); | |
| if (eslintFixMap) { | |
| // 本次 message 中實際存在的 key,用於後續清理過期的 fix | |
| const currentKeys = new Set<string>(); | |
| message.markers.forEach((m: TMarker) => { | |
| if (m.fix) { | |
| const key = `${m.code.value}|${m.startLineNumber}|${m.endLineNumber}|${m.startColumn}|${m.endColumn}`; | |
| currentKeys.add(key); | |
| eslintFixMap.set(key, m.fix); | |
| } | |
| }); | |
| // 清理本次未出現的 key,避免保留已不存在 marker 的舊 fix | |
| for (const key of Array.from(eslintFixMap.keys())) { | |
| if (!currentKeys.has(key)) { | |
| eslintFixMap.delete(key); | |
| } | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不确定这样是否正确
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Fixes #1079
globalCache.get("eslint-fix")為 undefined #1079问题描述:
在某些情况下(例如 Service Worker 重启后),
globalCache.get("eslint-fix")返回undefined,导致 Monaco Editor 中的 ESLint 自动修复功能无法正常工作,报错或无响应。修复内容:
globalCache的依赖,避免缓存失效导致的问题。"eslint-fix"相关配置或状态,确保值实时可用。改动范围:
测试建议: