Reanimated 4.4.x animated components conflict with Restyle theme
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- react-native, typescript
Hướng nghiên cứu
Start at the getThemeValue logic shown in the issue and reproduce the crash with the createRestyleComponent/Animated.createAnimatedComponent example on React Native 0.86.0, Reanimated 4.4.1, and Restyle 2.4.5. Done means animated numeric theme-key values pass through as literal styles while unknown string keys retain typo detection; no file or test path is named in the report.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
While upgrading our app to RN 0.86.0 and bumping Reanimated from 4.2.2 to 4.4.1 some animated components started crashing the app. Specifically components animating props belonging to Shopify Restyle's theming, like borderRadius or zIndex. It seems the culprit its also a source of Reanimated performance improvements, which is one of the reasons we want to upgrade, so it would not be ideal to turn it off. Upon quite a bit of debugging with Claude this is the information I gathered:
When a theme-key prop (borderRadius, zIndex, spacing props, etc.) receives a value that is not a key in the corresponding theme scale, getThemeValue throws a hard error — even when the value is a valid literal style value such as a raw pixel number. This makes restyle stricter than peer theme-prop libraries (styled-system, dripsy), which pass unknown values through, and it turns benign upstream behavior into render crashes.
Current behavior
if (isThemeKey(theme, themeKey)) {
if (value && theme[themeKey][value] === undefined)
throw new Error(`Value '${value}' does not exist in theme['${String(themeKey)}']`);
return value ? theme[themeKey][value] : value;
}
Any truthy value that is not a theme key throws, regardless of whether it is a number (a legitimate literal) or a string (likely a typo).
react-native-reanimated 4.4.x ships a default-on feature flag FORCE_REACT_RENDER_FOR_SETTLED_ANIMATIONS, which - when an animation settles - spreads the
resolved animated style values onto the wrapped component as top-level props (in addition to style). When that wrapped component is a restyle createBox()/AnimatedBox, the settled numeric values arrive as theme-key props:
Value '13' does not exist in theme['borderRadii'] // animated borderRadius
Value '1' does not exist in theme['zIndices'] // animated zIndex
Expected behavior
A numeric value passed to a theme-key prop should be treated as a literal style value and passed through (this is how styled-system and dripsy behave), rather than throwing. Strings that are not theme keys are the genuine typo case and could still throw or warn. In short:
- borderRadius="m" and not a key -> likely a typo, throw/warn (current behavior, fine).
- borderRadius={13} -> a literal value, pass it through.
A passthrough-for-numbers default, or at minimum a configurable option, would restore compatibility without losing typo detection.
Also just leaving my thanks to the Shopify Restyle team, as I think this is the first problem we have encountered in 4 years of using the library.
To Reproduce
const ButtonContainer = createRestyleComponent<
VariantProps<Theme, 'buttonVariants'> & React.ComponentProps<typeof Box>,
Theme
>(restyleFunctions, Box);
const AnimatedButtonContainer = Animated.createAnimatedComponent(ButtonContainer);
const { borderRadii } = useTheme<Theme>();
const animatedContainerStyle = useAnimatedStyle(() => {
if (!containerWidth.value || !circularLoading) {
return {};
}
const borderRadius = interpolate(loadingProgress.value, [0, 1], [borderRadii.base, borderRadii.xxl]);
return {
height: circleSize,
borderRadius,
};
});
<AnimatedButtonContainer
style={animatedContainerStyle}
}>
{renderContentBox()}
</AnimatedButtonContainer>;
Platform:
- iOS
- Android
Environment
2.4.5
- Ngôn ngữ chính
- TypeScript
- Star
- 3.4k
- Fork
- 154
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
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 Shopify/restyle
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 15/100
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
-
Cannot make custom componentĐang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Tất cả issue của Shopify/restyle
Issue tương tự
-
MCP tool results drop structuredContent when text is only a summaryCó thể đã có người làm @Pankaj-bit361 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
n8n-io/nod#1474 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Clean-up indicator: two polish points from the dev look (kit clock spacing, row description)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
inblockio/siwx-oidc-matrix-server#101 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status:needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
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 72/100
pingdotgg/t3code#42253 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày