fix: React Native Codegen issue with version 0.84#284
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes React Native 0.84 integration issues around the getUserAttributes TurboModule/codegen contract by ensuring native callbacks return a consistent (non-null) attributes object and by aligning the TypeScript spec with that behavior.
Changes:
- iOS: sanitize user attributes to exclude null/NSNull values before returning them via callback.
- Android: always invoke
getUserAttributescallback with(null, emptyMap)when no user is found (instead of invoking with no args). - TypeScript codegen spec: remove
nullfromUserAttributesvalue union and makegetUserAttributescallback result non-nullable.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| js/codegenSpecs/NativeMParticle.ts | Tightens UserAttributes and getUserAttributes callback typing for codegen. |
| ios/RNMParticle/RNMParticle.mm | Filters null values out of user attributes before returning to JS. |
| android/src/main/java/com/mparticle/react/MParticleModule.kt | Ensures callback is invoked with consistent (error, result) args even when user is missing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
js/codegenSpecs/NativeMParticle.ts
Outdated
| export type UserAttributes = { | ||
| [key: string]: string | string[] | number | boolean | null; | ||
| [key: string]: string | string[] | number | boolean; | ||
| }; |
There was a problem hiding this comment.
UserAttributes still uses the string[] shorthand. The PR description indicates this shorthand is unsupported by RN 0.84 codegen, so this change likely doesn’t resolve the reported build failure. Prefer Array<string> here (matching setUserAttributeArray) to avoid TSArrayType shorthand in the codegen spec.
| } else { | ||
| callback.invoke() | ||
| callback.invoke(null, WritableNativeMap()) | ||
| } |
There was a problem hiding this comment.
There are Android unit tests for other user methods, but this updated getUserAttributes behavior (always invoking the callback with (null, emptyMap) when the user is missing) isn’t covered. Add a test to assert the callback is invoked with two arguments and that the second argument is an empty map when selectedUser is null.
`NativeMParticle.ts (line 6) uses TSArrayType shorthand (string[]) which is unsupported by the React Native codegen` Made the types more flexible to support the new React Native 0.84.0 version. - In RNMParticle.mm, added sanitization for user attributes to exclude null values before returning them in the callback. - Updated TypeScript definitions to reflect the changes in callback result types.
7def449 to
7507daf
Compare
Summary
The app compilation failed when integrated into an app that uses React Native 0.84.
NativeMParticle.ts (line 6) uses TSArrayType shorthand (string[]) which is unsupported by the React Native codegenRemoved the null type in the mapTesting Plan
Tested locally with
0.76.9and0.84Master Issue
Closes https://go.mparticle.com/work/REPLACEME