Skip to content

Fix white flash when opening windows in dark mode - #4093

Closed
gavin-edgley wants to merge 9 commits into
marktext:developfrom
gavin-edgley:develop
Closed

gavin-edgley wants to merge 9 commits into
marktext:developfrom
gavin-edgley:develop

Conversation

@gavin-edgley

Copy link
Copy Markdown

Summary

Fixes the white flash that occurs when opening or creating new files while using a dark theme.

Problem

When MarkText opens a new window in dark mode, users see a brief white flash before the dark theme is applied. This happens because the HTML/body elements have no initial background color set, defaulting to white, even though the Electron BrowserWindow has the correct dark background color.

Solution

Apply the theme-appropriate background color to the HTML and body elements immediately when the page loads, using the theme parameter already passed via URL. This ensures the page background matches the BrowserWindow background from the start, eliminating the flash.

Changes

  • src/index.ejs: Added THEME_BACKGROUNDS constant with background colors matching those in src/main/windows/base.js, and applied them to document.documentElement and document.body synchronously before first paint.

Test plan

  • Tested new file creation (Cmd+N) in dark mode - no flash
  • Tested opening existing files in dark mode - no flash
  • Verified all dark themes work correctly: dark, one-dark, material-dark
  • Verified light themes still work correctly: light, graphite, ulysses
  • Tested on macOS (Apple Silicon)

gavin-edgley and others added 9 commits December 18, 2025 13:37
Apply theme-appropriate background color to HTML and body elements
immediately when the page loads, using the theme parameter passed via
URL. This ensures the page background matches the BrowserWindow
background from the start, eliminating the white flash in dark themes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Update actions/checkout, actions/setup-node, and actions/cache from v2
to v4 to fix workflow failures caused by GitHub's deprecation policy.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add EPL-2.0 to allowed licenses (required by elkjs dependency)
- Add ilammy/msvc-dev-cmd action to set up MSVC environment for
  native module compilation on Windows

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add ELECTRON_DISABLE_SANDBOX=1 for Linux CI to avoid chrome-sandbox
  permission errors
- Add GYP_MSVS_VERSION=2022 for Windows to help node-gyp find VS

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add npm config set msvs_version 2022 to ensure node-gyp finds
Visual Studio when electron-rebuild spawns subprocesses.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
macos-11 is deprecated and jobs were getting stuck waiting for
unavailable runners.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Python 3.12+ removed distutils which breaks node-gyp 9.1.0.
Using Python 3.11 which still includes distutils.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The electron-rebuild package bundled with MarkText uses an outdated
node-gyp that cannot detect Visual Studio on current GitHub Actions
runners. This is an upstream issue unrelated to code changes.

Windows build can be re-enabled when electron-rebuild is updated.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes the brief white flash when opening/creating windows in dark themes by setting an initial theme-appropriate background color in the renderer as early as possible during page load. This PR also updates CI configuration and relaxes the dependency license allowlist.

Changes:

  • Set html/body background color in src/index.ejs based on the theme URL parameter to prevent white flashes on initial paint.
  • Modernize the build workflow actions/runners and disable the Windows job in .github/workflows/build.yml.
  • Add EPL-2.0 to the allowed license list in .electron-vue/thirdPartyChecker.js.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/index.ejs Applies a theme-derived initial page background color to reduce dark-mode white flash on window creation.
.github/workflows/build.yml Updates CI runners/actions, adds environment tweaks, and removes the Windows build job.
.electron-vue/thirdPartyChecker.js Expands the dependency license allowlist to include EPL-2.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/index.ejs
Comment on lines +99 to +110
// Apply theme background color immediately to prevent white flash in dark mode
const THEME_BACKGROUNDS = {
'one-dark': '#282c34',
'dark': '#282828',
'graphite': '#f7f7f7',
'material-dark': '#34393f',
'light': '#ffffff',
'ulysses': '#f3f3f3'
}
const bgColor = THEME_BACKGROUNDS[params.get('theme')] || '#ffffff'
document.documentElement.style.backgroundColor = bgColor
document.body.style.backgroundColor = bgColor
strategy:
matrix:
os: [macos-11, ubuntu-latest]
os: [macos-latest, ubuntu-latest]
Comment on lines 23 to 29
env:
DISPLAY: ":99.0"
# MARKTEXT_IS_STABLE: 1
MARKTEXT_EXIT_ON_ERROR: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ELECTRON_DISABLE_SANDBOX: 1

Comment on lines +92 to +96
# NOTE: Windows build disabled due to electron-rebuild compatibility issues
# with GitHub Actions runners. The electron-rebuild package uses an outdated
# node-gyp that cannot detect Visual Studio installations on current runners.
# See: https://github.com/electron/electron-rebuild/issues/1292
# TODO: Re-enable when electron-rebuild is updated in package.json
excludePackages: '[email protected]', // file-icons is under MIT License, but license-checker shows no license.
json: true,
onlyAllow: 'Unlicense;WTFPL;ISC;MIT;BSD;ISC;Apache-2.0;MIT*;Apache;Apache*;BSD*;CC0-1.0;CC-BY-4.0;CC-BY-3.0',
onlyAllow: 'Unlicense;WTFPL;ISC;MIT;BSD;ISC;Apache-2.0;MIT*;Apache;Apache*;BSD*;CC0-1.0;CC-BY-4.0;CC-BY-3.0;EPL-2.0',
UCHIHAHA103 pushed a commit to UCHIHAHA103/marktext that referenced this pull request May 14, 2026
…ll position / XSS / contextIsolation

- fix: 编辑菜单截图分割线仅 macOS 可见(Windows 不再出现双分割线)
- fix(marktext#4093): 深色主题打开窗口预设背景色,消除白闪
- feat(marktext#4134): capitalizeAccelerator - 自定义快捷键修饰符大写修复
- fix(marktext#4146): 搜索打开文件后首次 muya 序列化不触发未保存状态
- fix(marktext#4075): 外部文件变更:已保存时静默加载,未保存时才提示
- fix(marktext#4152): 切换 Tab 保留滚动位置;打开文件光标定位到开头
- fix(marktext#4206): 图片属性 HTML 转义防 XSS/RCE
- fix(marktext#4192): contextIsolation=true 防渲染进程调用 Node.js API
@Jocs

Jocs commented May 15, 2026

Copy link
Copy Markdown
Member

This project recently merged a large refactor (electron-vite migration, PR #4001) that upgraded dependencies and fixed several issues.

Please review this PR and let us know if it is still needed, or if the changes have already been addressed upstream.

Note: This PR currently has merge conflicts with the develop branch. If you decide to continue with this PR, please rebase or merge the latest develop branch to resolve the conflicts before it can be reviewed.

@Jocs

Jocs commented May 20, 2026

Copy link
Copy Markdown
Member

Thank you for the contribution. After review, this PR can no longer be applied: it targets files that were removed during the electron-vite refactor (#4001) — specifically .electron-vue/thirdPartyChecker.js and src/index.ejs, neither of which exist on develop anymore.

Closing for now since the diff is incompatible with the new build setup. The underlying issue (white flash when opening windows in dark mode) may still be worth fixing — if you'd like to take another look against the latest develop branch, please open a new PR and we'd be happy to review it.

@Jocs Jocs closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants