asBaseComponent: stale module-level colorScheme prevents re-render on scheme switch back
Maintainer thường phản hồi trong vòng 1 ngày
@huytdps13400 đang làm issue này rồi.
Từ ngày 4/10/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, react-native
- Lĩnh vực
- frontend, mobile-dev
Hướng nghiên cứu
Bắt đầu trong src/commons/asBaseComponent.js và kiểm tra cách BaseComponent khởi tạo trạng thái colorScheme và đăng ký appearanceListener. Tái hiện chuỗi chuyển đổi light-to-dark-to-light với các component được mount sau thay đổi đầu tiên. Được xem là hoàn tất khi các component RNUI bị ảnh hưởng re-render đúng cách theo cả hai hướng mà không giữ lại các màu đã lỗi thời.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
asBaseComponent HOC captures colorScheme as a module-level constant at import time. Since BaseComponent extends React.PureComponent (via UIComponent), components mounted after a scheme change hold a stale state.colorScheme that matches the original scheme. When switching back to that original scheme, the appearanceListener guard (this.state.colorScheme !== colorScheme) evaluates to false, skipping setState and preventing re-render.
Related to
- Components
- Demo
- Docs
- Typings
Steps to reproduce
- App starts in light mode → module-level
colorSchemeis captured as'light' - Go to a settings/appearance screen and switch to dark mode → all RNUI components re-render correctly
- Navigate to any screen — new components mount during dark mode with
state.colorScheme = 'light'(stale module-level value) - Switch back to light mode →
Scheme.broadcastSchemeChange('light')fires - Stale components check
'light' !== 'light'→false→setStateis never called → no re-render
Expected behavior
All RNUI components (Text, View, Button, Switch, etc.) should re-render with the updated color scheme when switching in both directions (light → dark AND dark → light).
Actual behavior
Components mounted after the first scheme change do not re-render when switching back to the original scheme. They retain the previous scheme's colors (e.g., light gray text on a light background) because BaseComponent (a PureComponent) skips rendering — both props and state appear unchanged.
More Info
Code snippet
The bug is in src/commons/asBaseComponent.js:
// Line 8 — evaluated ONCE at module load, never updated
const colorScheme = Scheme.getSchemeType();
function asBaseComponent(WrappedComponent, options = {}) {
// BaseComponent extends UIComponent which extends React.PureComponent
class BaseComponent extends UIComponent {
state = {
error: false,
colorScheme // All instances get the stale module-level value
};
appearanceListener = colorScheme => {
// This guard fails for stale instances when switching back to the original scheme
if (this.state.colorScheme !== colorScheme) {
this.setState({ colorScheme });
}
};
}
}
Fix — evaluate Scheme.getSchemeType() per instance instead of once at module level:
const EMPTY_MODIFIERS = {};
-const colorScheme = Scheme.getSchemeType();
function asBaseComponent(WrappedComponent, options = {}) {
class BaseComponent extends UIComponent {
state = {
error: false,
- colorScheme
+ colorScheme: Scheme.getSchemeType()
};
Screenshots/Video
N/A — the visual symptom is dark-theme text colors (e.g., #C9D6DF) rendered on a light-theme background (#F0F5F9), causing text to blend/disappear.
Environment
- React Native version: 0.83
- React Native UI Lib version: 8.3.4
Affected platforms
- Android
- iOS
- Web
- Ngôn ngữ chính
- TypeScript
- Star
- 7.2k
- Fork
- 749
- Merge trung bình
- 29 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của wix/react-native-ui-lib
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
wix/react-native-ui-lib#4022 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SortableGridList does not forward props to its inner ScrollView (inconsistent with SortableList)Có thể đã có người làm @yinminqian đã nhận 171 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
wix/react-native-ui-lib#4002 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
RN 0.85.0 StyleSheet.absoluteFillObject is removedCó thể đã có người làm @ChrisJamesC đã nhận 78 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
wix/react-native-ui-lib#3965 · 3 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
wix/react-native-ui-lib#4044 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
wix/react-native-ui-lib#4043 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của wix/react-native-ui-lib
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 2 ngày
-
reproduced
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
anomalyco/opencode#62052 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
strapi/design-system#2084 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Report: &TV InternationalĐang mởcheck:passed streams:remove
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
OAuth documentation for GET /api/v2/users/me/ appears inconsistent with required global read scopeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày