Ant Design StyleAnt Design Style
Quick Start
Best Practices
API Reference
Release Notes
⌘ K

Table of Contents

Flashing Issue in Dark Mode
SSR Solution
Best Practices and Case Studies
Writing Style
CSS Modules Global Style Override Migration
Writing Linked Styles for Parent-Child Components
Theme Customization
Customizing Ant Design Component Styles
Extending Custom Token Type Definition
Failure of antd Static Methods to Respond to Themes
Theme Switching
Flashing Issue in Dark Mode
UI Library Development
🚧 Styling Best Practices for Customizing Components Based on antd v5
Style Cases
Clay Style UI
Custom Component —— macOS Selector
Style Components
PREV
Failure of antd Static Methods to Respond to Themes
NEXT
🚧 Styling Best Practices for Customizing Components Based on antd v5

相关资源

Ant Design
Ant Design Pro
Ant Design Pro Components
Umi-React 应用开发框架
Dumi-组件/文档研发工具
qiankun-微前端框架

社区

Medium
Twitter
yuqueAnt Design 语雀专栏
Ant Design 知乎专栏
体验科技专栏
seeconfSEE Conf-SEE Conf-蚂蚁体验科技大会

帮助

GitHub
更新日志
讨论

more products更多产品

yuque语雀-知识创作与分享工具
AntVAntV-数据可视化解决方案
EggEgg-企业级 Node.js 框架
kitchenKitchen-Sketch 工具集
xtech蚂蚁体验科技
Copyright © 2022-2024
Made with ❤️ by 蚂蚁集团 - AFX & 数字科技
‌
‌
‌
‌

Flashing Issue in Dark Mode

When using antd-style, the initial screen is generally in light mode. This causes the interface to first display the light theme and then switch to the dark theme in dark mode. This gives users a "flashing" feeling, resulting in a poor experience. This type of problem is known as FOUC (Flash of Unstyled Content).

How to solve it?

This article assumes that you already understand the solutions for antd-style in SSG and SSR.

Principle analysis:

  1. SSG generates light-colored HTML;
  2. After JS hydration, cssinjs runs and re-generates dark class names and styles;

The root cause of FOUC is that the server does not know the client's current theme status.

Therefore, there are two solutions:

  1. SSR: Make the server aware of the user client's theme status, for example, using query URLs, cookies, and other mechanisms;
  2. Extract color variables as CSS variables;

SSR Solution

Using next.js App Router as an example:

tsx
tsx