Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): allow null value for AppEventsLogger.setUserID #213

Merged
merged 2 commits into from Mar 4, 2022

Conversation

danilobuerger
Copy link
Contributor

AppEventsLogger.clearUserID is deprecated and suggests using "setUserID(null)"
However, setUserID is currently not typed to allow null values.

Test Plan:

no test plan

AppEventsLogger.clearUserID is deprecated and suggests using "setUserID(null)"
However, setUserID is currently not typed to allow null values.
src/FBAppEventsLogger.ts Outdated Show resolved Hide resolved
@@ -292,7 +292,7 @@ export default {
* Sets a custom user ID to associate with all app events.
* The userID is persisted until it is cleared by clearUserID method.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* The userID is persisted until it is cleared by clearUserID method.
* The userID is persisted unless it is cleared by calling this method again with a null userID

Copy link
Collaborator

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh of course! Should have noticed that when I deprecated the clearUserID method during the forward-port - thanks for catching this. I updated the method doc to match, looks +1

@mikehardy mikehardy changed the title Allow null values for AppEventsLogger.setUserID fix(types): allow null value for AppEventsLogger.setUserID Mar 4, 2022
@mikehardy mikehardy added the pending-merge Just waiting on clean CI test run. Any maintainer should feel free to merge if CI is passing. label Mar 4, 2022
@mikehardy mikehardy merged commit 72f861b into thebergamo:master Mar 4, 2022
@mikehardy mikehardy removed the pending-merge Just waiting on clean CI test run. Any maintainer should feel free to merge if CI is passing. label Mar 4, 2022
@danilobuerger
Copy link
Contributor Author

@mikehardy Thanks for merging it so quickly. Although I just noticed that calling setUserID(null) now breaks Android. On the android side it doesn't like null but wants clearUserID. Its a shame that iOS and Android are out of sync like that.

@danilobuerger danilobuerger deleted the patch-1 branch March 4, 2022 16:22
@mikehardy
Copy link
Collaborator

mikehardy commented Mar 4, 2022

@danilobuerger are you 100% on that? Because I thought they both made that change

In the current version they internally delegate clearUserId to setUserId(null):
https://github.com/facebook/facebook-android-sdk/blob/ec96d8a0d3fffa3176ef985819650a68e1ba84bb/facebook-core/src/main/java/com/facebook/appevents/AppEventsLogger.kt#L504-L506

and the internal implementation of setUserId explicitly has the id string arg set as nullable
https://github.com/facebook/facebook-android-sdk/blob/ec96d8a0d3fffa3176ef985819650a68e1ba84bb/facebook-core/src/main/java/com/facebook/appevents/AnalyticsUserIDStore.kt#L46

So at least with the current release I expect it should work. However, "the current release" is v13 and we're still pulling in facebook-android-sdk v12 until #208

on their v12.2 branch it appears to work as well though? https://github.com/facebook/facebook-android-sdk/blob/a6e982175b258fbd99ec8313bbe052f1efd90185/facebook-core/src/main/java/com/facebook/appevents/AppEventsLogger.kt#L498-L500

Except one thing I do see is that setUserId() method is marked with not-null in the Kotlin! So perhaps that's the problem? What exact problem did you see?

We could maybe log an issue for them to true up their types and deprecate clearUserId similar to facebook-ios-sdk

In the meantime if this is breaking things or requiring platform-specific code that's a bug in my way of thinking. For Android we could make setUserId(null) at the javascript layer call native clearUserId() - a quick PR and I'd merge it if you liked the idea and posted it up

@danilobuerger
Copy link
Contributor Author

Except one thing I do see is that setUserId() method is marked with not-null in the Kotlin! So perhaps that's the problem? What exact problem did you see?

Yeah, that seems to be the problem. I get an error exactly there that a null value is passed to a non null parameter in kotlin.

In the meantime if this is breaking things or requiring platform-specific code that's a bug in my way of thinking. For Android we could make setUserId(null) at the javascript layer call native clearUserId() - a quick PR and I'd merge it if you liked the idea and posted it up

Yup, will submit a PR later today

@mikehardy
Copy link
Collaborator

Awesome! Thanks in advance. I'll chase down facebook-android-sdk in parallel with an issue over there

github-actions bot pushed a commit that referenced this pull request Mar 4, 2022
### [7.3.3](v7.3.2...v7.3.3) (2022-03-04)

### Bug Fixes

* **android, setUserId:** temporary android workaround for using setUserID(null) ([#214](#214)) ([231f969](231f969))
* **types:** allow null value for AppEventsLogger.setUserID ([#213](#213)) ([72f861b](72f861b))
@github-actions
Copy link

github-actions bot commented Mar 4, 2022

🎉 This PR is included in version 7.3.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mikehardy
Copy link
Collaborator

Upstream already merged the fix sweet! It'll be in whatever is after 13.0.0 whenever that is, and whenever we can access it via forward-porting here :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants