Skip to content

🐛 [4.19.0] Codegen fails with "Unknown prop type: undefined" errors on New Architecture #3496

@dmk3141618

Description

@dmk3141618

Description

After upgrading to react-native-screens 4.19.0, builds fail with multiple Codegen errors when using New Architecture. The errors occur in several fabric component files.

Error Messages

node_modules/react-native-screens/src/fabric/SearchBarNativeComponent.ts:
Unknown prop type for "onSearchFocus": "undefined"

node_modules/react-native-screens/src/fabric/ScreenStackHeaderConfigNativeComponent.ts:
Unknown prop type for "onAttached": "undefined"

Steps to Reproduce

  1. Create a React Native project with New Architecture enabled
  2. Install [email protected]
  3. Run the build (yarn ios or yarn android)
  4. Build fails with Codegen errors

Root Cause Analysis

Issue 1: | null union type in SearchBarNativeComponent.ts

In src/fabric/SearchBarNativeComponent.ts (lines 40-44, 63-64), event handler props use | null union type:

onSearchFocus?: CT.DirectEventHandler<SearchBarEvent> | null;
onSearchBlur?: CT.DirectEventHandler<SearchBarEvent> | null;
onSearchButtonPress?: CT.DirectEventHandler<SearchButtonPressedEvent> | null;
onCancelButtonPress?: CT.DirectEventHandler<SearchBarEvent> | null;
onChangeText?: CT.DirectEventHandler<ChangeTextEvent> | null;
// ...
onClose?: CT.DirectEventHandler<SearchBarEvent> | null;
onOpen?: CT.DirectEventHandler<SearchBarEvent> | null;

The React Native Codegen TypeScript parser doesn't recognize | null union types and interprets them as undefined.

Issue 2: Potential issues in ScreenStackHeaderConfigNativeComponent.ts

In src/fabric/ScreenStackHeaderConfigNativeComponent.ts:

  • Line 50: backTitleVisible?: CT.WithDefault<boolean, 'true'> - string 'true' used as default for boolean type
  • Lines 75-76: CT.UnsafeMixed[] type may cause Codegen parsing issues
backTitleVisible?: CT.WithDefault<boolean, 'true'>;  // should be `true` not `'true'`?
headerLeftBarButtonItems?: CT.UnsafeMixed[];
headerRightBarButtonItems?: CT.UnsafeMixed[];

Suggested Fix

For SearchBarNativeComponent.ts

Remove the | null union from event handler type definitions:

- onSearchFocus?: CT.DirectEventHandler<SearchBarEvent> | null;
+ onSearchFocus?: CT.DirectEventHandler<SearchBarEvent>;

The ? optional modifier already handles the case where these props might not be provided.

Workaround

Using patch-package to remove | null from SearchBarNativeComponent.ts resolves the first error, but then the ScreenStackHeaderConfigNativeComponent.ts error appears.

patches/react-native-screens+4.19.0.patch (partial fix)
diff --git a/node_modules/react-native-screens/src/fabric/SearchBarNativeComponent.ts b/node_modules/react-native-screens/src/fabric/SearchBarNativeComponent.ts
index df774b9..51864ad 100644
--- a/node_modules/react-native-screens/src/fabric/SearchBarNativeComponent.ts
+++ b/node_modules/react-native-screens/src/fabric/SearchBarNativeComponent.ts
@@ -37,11 +37,11 @@ type AutoCapitalizeType =
 type OptionalBoolean = 'undefined' | 'false' | 'true';

 export interface NativeProps extends ViewProps {
-  onSearchFocus?: CT.DirectEventHandler<SearchBarEvent> | null;
-  onSearchBlur?: CT.DirectEventHandler<SearchBarEvent> | null;
-  onSearchButtonPress?: CT.DirectEventHandler<SearchButtonPressedEvent> | null;
-  onCancelButtonPress?: CT.DirectEventHandler<SearchBarEvent> | null;
-  onChangeText?: CT.DirectEventHandler<ChangeTextEvent> | null;
+  onSearchFocus?: CT.DirectEventHandler<SearchBarEvent>;
+  onSearchBlur?: CT.DirectEventHandler<SearchBarEvent>;
+  onSearchButtonPress?: CT.DirectEventHandler<SearchButtonPressedEvent>;
+  onCancelButtonPress?: CT.DirectEventHandler<SearchBarEvent>;
+  onChangeText?: CT.DirectEventHandler<ChangeTextEvent>;
   hideWhenScrolling?: CT.WithDefault<boolean, true>;
   autoCapitalize?: CT.WithDefault<AutoCapitalizeType, 'systemDefault'>;
   placeholder?: string;
@@ -60,8 +60,8 @@ export interface NativeProps extends ViewProps {
   disableBackButtonOverride?: boolean;
   // TODO: consider creating enum here
   inputType?: string;
-  onClose?: CT.DirectEventHandler<SearchBarEvent> | null;
-  onOpen?: CT.DirectEventHandler<SearchBarEvent> | null;
+  onClose?: CT.DirectEventHandler<SearchBarEvent>;
+  onOpen?: CT.DirectEventHandler<SearchBarEvent>;
   hintTextColor?: ColorValue;
   headerIconColor?: ColorValue;
   shouldShowHintSearchIcon?: CT.WithDefault<boolean, true>;

Current workaround: Downgrade to [email protected]

Environment

  • react-native-screens: 4.19.0
  • react-native: 0.81.0
  • expo: 54.0.1
  • Architecture: New Architecture enabled
  • Platform: iOS / Android

Related

Metadata

Metadata

Assignees

Labels

Missing infoThe user didn't precise the problem enoughMissing reproThis issue need minimum repro scenario

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions