🐛 修复保存脚本改名后浏览器标签页标题未同步更新#1607
Open
cyfung1031 wants to merge 1 commit into
Open
Conversation
document.title 的更新只在切换标签(activeUuid 变化)时触发,保存后 即使脚本名已改变,当前激活标签的浏览器标题仍停留在旧名称,直到用户 切换标签或刷新页面。现改为依赖已解析的 i18n 名称,保存后立即同步。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Collaborator
Author
|
代码通过人工检查 & 用户已在真实浏览器中人工测试确认 |
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.
Checklist / 检查清单
背景
在脚本编辑器中修改脚本的
// @name并保存后,编辑器内部的标签栏(EditorTabs)会立即显示新名称,但浏览器实际的标签页标题(document.title)仍停留在旧名称,直到用户切换到其他标签再切回来,或刷新页面,标题才会更新。根因:
src/pages/options/routes/ScriptEditor/index.tsx中负责同步document.title的useEffect只依赖state.activeUuid,仅在切换激活标签时重新计算标题;保存脚本后activeUuid本身不变,因此该 effect 不会重新执行。本次改动
activeTab的useMemo提前声明,并新增activeTabScriptName(已解析的 i18n 名称字符串)。useEffect依赖数组由[state.activeUuid]改为[state.activeUuid, activeTabScriptName],使其在保存改名后立即重新计算document.title,同时避免了直接依赖整个state.tabs数组导致在每次按键编辑时都触发该 effect(因为markChangedaction 每次按键都会产出新的tabs数组引用)。验证
npx eslint src/pages/options/routes/ScriptEditor/index.tsx— 无报错npx tsc --noEmit -p .— 无新增报错(仅有与本次改动无关的tests/mocks/network.ts预置类型声明缺失)🤖 Generated with Claude Code