🐛 修复暗色模式下页面初次加载白屏闪烁的问题#1499
Closed
CodFrm wants to merge 1 commit into
Closed
Conversation
Collaborator
|
如果系统是深色,用户设定为 light mode, 会倒过来出现 dark flash AppContext.tsx 的载入已经是 React 在跑, 但问题是 React 跑之前。改
|
Member
Author
应该不是,是另外的问题,我再调整一下 |
Collaborator
我把 #1498 改好了。也测试好了。你看看吧 |
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 / 检查清单
Description / 描述
fix #1497
问题:暗色主题下,options / popup / install 等页面初次加载时会先白屏一闪。根因是
arco-theme属性由 React 挂载时的 JS(AppContext.tsx)设置,在此之前模板内联样式里的var(--color-bg-2)无定义,body 回退为白色。方案(结合 issue 中两边的讨论):
三个 HTML 模板(
options.html/popup.html/template.html)的内联样式中增加系统暗色兜底,仅在主题尚未初始化时生效:AppContext.tsx的 light 分支由removeAttribute("arco-theme")改为显式setAttribute("arco-theme", "light"),使body:not([arco-theme])精确等价于"JS 尚未初始化主题"。这样不需要 issue 里原始提案中的:has(#root:empty)(回应 @cyfung1031 对:has的性能顾虑),同时让index.css中已有的body[arco-theme='light']滚动条规则真正生效(此前是死代码)。各场景行为:
测试:
e2e/theme-flash.spec.ts:通过 CDPEmulation.setScriptExecutionDisabled固定"React 挂载前"首帧状态,模拟系统暗色验证三个模板页面 body 背景为rgb(35, 35, 36),并验证亮色系统下无"黑闪"。修复前三个用例均失败(实测白色rgb(255, 255, 255)),修复后通过。src/pages/store/AppContext.test.tsx:验证 light / dark / auto 模式下arco-theme属性均被显式设置。验证结果:单测 959 全部通过;e2e 32 全部通过;
pnpm run lint0 错误。Screenshots / 截图
修复前(系统暗色、脚本执行前首帧,e2e 截图):body 为白色;修复后同状态 body 为
#232324。