From 3cfa2010dc6aa4b19ee2394ad8db862150a018cf Mon Sep 17 00:00:00 2001 From: Isaac Rowntree Date: Fri, 20 Mar 2026 13:04:16 +1100 Subject: [PATCH] fix(TextInput): fall back to theme fontWeight when style doesn't provide one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both TextInputOutlined and TextInputFlat destructure `fontWeight` from the user's `style` prop and spread it after the theme font object: const { fontWeight } = StyleSheet.flatten(style) || {}; textStyle: { ...font, fontWeight } When the user doesn't set `fontWeight` in their style, the destructured value is `undefined`. Spreading `{ ...font, fontWeight: undefined }` then overrides `font.fontWeight` (e.g. '400' from the theme) with `undefined`. On React Native's Fabric renderer (New Architecture), this `undefined` flows through as nil to the native `RCTGetFontWeight` function, which passes it to `CFStringFind` → `CFStringGetLength` on a NULL pointer → EXC_BAD_ACCESS (SIGSEGV). The fix renames the destructured variable to `fontWeightStyle` and uses nullish coalescing to fall back to the theme font's fontWeight: const fontWeight = fontWeightStyle ?? font.fontWeight; This preserves the existing behavior when `fontWeight` IS provided in the style prop, while preventing the nil crash when it isn't. --- src/components/TextInput/TextInputFlat.tsx | 3 ++- src/components/TextInput/TextInputOutlined.tsx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/TextInput/TextInputFlat.tsx b/src/components/TextInput/TextInputFlat.tsx index 378366e176..447bf810c2 100644 --- a/src/components/TextInput/TextInputFlat.tsx +++ b/src/components/TextInput/TextInputFlat.tsx @@ -88,12 +88,13 @@ const TextInputFlat = ({ const { fontSize: fontSizeStyle, lineHeight: lineHeightStyle, - fontWeight, + fontWeight: fontWeightStyle, height, paddingHorizontal, textAlign, ...viewStyle } = (StyleSheet.flatten(style) || {}) as TextStyle; + const fontWeight = fontWeightStyle ?? font.fontWeight; const fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE; const lineHeight = lineHeightStyle || (Platform.OS === 'web' ? fontSize * 1.2 : undefined); diff --git a/src/components/TextInput/TextInputOutlined.tsx b/src/components/TextInput/TextInputOutlined.tsx index 70b590fabb..03bc6732d4 100644 --- a/src/components/TextInput/TextInputOutlined.tsx +++ b/src/components/TextInput/TextInputOutlined.tsx @@ -90,13 +90,14 @@ const TextInputOutlined = ({ const { fontSize: fontSizeStyle, - fontWeight, + fontWeight: fontWeightStyle, lineHeight: lineHeightStyle, height, backgroundColor = colors?.background, textAlign, ...viewStyle } = (StyleSheet.flatten(style) || {}) as TextStyle; + const fontWeight = fontWeightStyle ?? font.fontWeight; const fontSize = fontSizeStyle || MAXIMIZED_LABEL_FONT_SIZE; const lineHeight = lineHeightStyle || (Platform.OS === 'web' ? fontSize * 1.2 : undefined);