[v1.3] 修复编辑器中 ESLint 修复功能失效的问题(globalCache.get("eslint-fix") 为 undefined)- 修复 #1079#1184
Open
cyfung1031 wants to merge 10 commits intoscriptscat:release/v1.3from
Open
[v1.3] 修复编辑器中 ESLint 修复功能失效的问题(globalCache.get("eslint-fix") 为 undefined)- 修复 #1079#1184cyfung1031 wants to merge 10 commits intoscriptscat:release/v1.3from
cyfung1031 wants to merge 10 commits intoscriptscat:release/v1.3from
Conversation
This was referenced Feb 7, 2026
Contributor
There was a problem hiding this comment.
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 |
Comment on lines
+257
to
+263
| 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); | ||
| } | ||
| }); |
There was a problem hiding this comment.
这里把 eslintFixMap 作为全局 Map 只做 set、不做清理,会留下已不存在 marker 的旧 fix;更关键的是当同一个 key 的 marker 之后不再提供 fix 时,旧值仍会被命中,导致 Quick Fix 显示/应用过期修复。建议每次收到 message 时先按当前 editor/model 重建(或至少先删除本次 message 未包含 fix 的 key),并考虑按 model.uri 或 editor id 做隔离,避免不同编辑器之间相互污染。
Suggested change
| 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); | |
| } | |
| } |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
Fixes #1079
globalCache.get("eslint-fix")為 undefined #1079问题描述:
在某些情况下(例如 Service Worker 重启后),
globalCache.get("eslint-fix")返回undefined,导致 Monaco Editor 中的 ESLint 自动修复功能无法正常工作,报错或无响应。修复内容:
globalCache的依赖,避免缓存失效导致的问题。"eslint-fix"相关配置或状态,确保值实时可用。改动范围:
测试建议: