Repository navigation
fix: [SDK-5698] let initialize and login reach native - #1205
abdulraqeeb33 wants to merge 2 commits into
Conversation
Both guards returned before calling native. Initialize was the damaging one: native falls back to the cached app id, and short-circuiting skipped that fallback, leaving the SDK unstarted so the next login failed. Null is not a concern here. Dart null safety is on (sdk >=2.12.0) and both parameters are non-nullable String, so a Dart caller cannot pass null and isMissing could only ever catch an empty string. Native handles empty on both platforms: Android falls back to the cached app id after the never-crash change, and iOS initialize: rejects "" through OSInputGuard. The alias, email, SMS, tag, trigger, and outcome guards stay. Dropping the last isMissing call made the utils import unused; flutter analyze flagged it and it is removed. The test that asserted an empty externalId never reached the channel now asserts it is forwarded. DO NOT MERGE until oneSignalVersion in android/build.gradle can be bumped to a release containing the never-crash change. It pins 5.11.0, where an empty app id does not yet fall back to the cached one. Co-authored-by: Cursor <cursoragent@cursor.com>
d1c8f7c to
a0a8aa2
Compare
| @@ -49,7 +48,6 @@ class OneSignal { | |||
| /// The initializer accepts an [appId] which the developer can get | |||
| /// from the OneSignal consoleas well as a dictonary of [launchOptions] | |||
| static Future<void> initialize(String appId) async { | |||
There was a problem hiding this comment.
Non-blocking: no test covers initialize('') now. Could you add one asserting '' is forwarded and the lifecycle methods still run? As is, restoring the old guard would still pass the suite.
There was a problem hiding this comment.
Agreed, and the part that matters is your point that restoring the old guard would still pass the suite as written. Not added yet.
There was a problem hiding this comment.
Now added in 685a8eb. Asserts '' is forwarded and that the lifecycle methods still run. Revert-checked: restoring the guard turns it red, which was your actual point.
| static Future<void> initialize(String appId) async { | ||
| if (isMissing(appId, 'initialize: appId')) return; | ||
| await _channel.invokeMethod('OneSignal#initialize', {'appId': appId}); | ||
| await Future.wait([ |
There was a problem hiding this comment.
Nit: initialize('') after a valid init now reruns lifecycleInit, which clears pending foreground display/preventDefault caches (OSFlutterNotifications.m:124). Same as calling initialize twice today, so fine to leave.
There was a problem hiding this comment.
Noted, and agreed it matches calling initialize twice today.
| expect(channelController.state.externalId, isNull); | ||
| }); | ||
| test( | ||
| 'login forwards an empty externalId to native, which ignores it', |
There was a problem hiding this comment.
Nit: the name says native ignores it, but the test only checks forwarding. Maybe "login forwards an empty externalId to native".
There was a problem hiding this comment.
Agreed, the name claims more than the test checks.
|
Both fair. The missing Holding both until the blocker is resolved: this needs |
The suite had no case for an empty appId, so restoring the old guard would still have passed. The new test asserts '' is forwarded and that the lifecycle methods still run; reverting the guard turns it red. The login test name claimed native ignores the value when the test only checks forwarding, so it now says what it checks. Review feedback from fadi-george on #1205. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Follow-up: both actionable ones are fixed in 685a8eb, including the |
|
@abdulraqeeb33 title is still react-native, this is flutter |
Important
Blocked on the never-crash rollout, not just an AAR/version bump. See "Why this cannot merge yet" below. Native's never-crash behavior sits behind
SDK_NEVER_CRASH_ENABLED, which defaults to off, and the legacy path still throws on a null.Description
One Line Summary
Remove input validation that was added to the wrapper by mistake, so the native SDK owns it.
Details
Motivation: this undoes a wrapper-side mistake
SDK-5327 added null and empty checks to every client SDK at once, wrappers included. For most APIs that was harmless duplication. For
initializeandloginit was the wrong layer, and it caused a bug.Validation belongs in the native SDK. It is the only layer that knows what an invalid input should actually do, and duplicating it per wrapper means six implementations drifting from each other and from native. The wrapper's job is to pass the call through.
initializeshows why this matters concretely. Native falls back to the app ID cached by an earlier launch when the one it is given is unusable. The wrapper guard returned before native was ever called, so that fallback never ran, the SDK stayed unstarted, and the nextloginfailed. The wrapper was not preventing a bug, it was creating one. That is the SDK-5366 chain, and the fix is to delete the guard rather than to catch the symptom downstream.So this PR is a correction, not a feature: the check should have gone into native in the first place.
Why this cannot merge yet
Native Android's never-crash behavior is behind a remote feature flag, and it is off by default:
When the flag is off,
NeverCrashKillSwitch.create()returns the legacyOneSignalImp, which still throws by design:The helper is commented "The kill switch's fallback keeps the crash a Java null used to hit in the non-null facade." The nullable signatures from #2841 are real, but the log-and-ignore behavior behind them only applies on the V2 path.
So merging needs both:
SDK_NEVER_CRASH_ENABLEDactually rolled out, since the flag is evaluated per app from mirrored startup flags.Until then, removing the guard reintroduces exactly the SDK-5304 crash for every app the flag has not reached. My original description claimed Android already logs and ignores a null; that was wrong, and it was wrong in the same way across all six wrapper PRs.
Scope
Only
initializeandlogininlib/onesignal_flutter.dart.The alias, email, SMS, tag, trigger, and outcome guards stay, along with the Live Activity and
removeGroupedNotificationschecks.Removing the last
isMissingcall in this file left thesrc/utils.dartimport unused.flutter analyzeflagged it, so it is removed.Testing
Unit testing
test/onesignalflutter_test.darthad a test asserting an emptyexternalIdnever reached the channel. It now asserts the value is forwarded, which is the new contract.Full suite: 272 passed.
flutter analyze lib testreports no issues.Manual testing
Not exercised on a device. It cannot be meaningfully exercised until the dependency bump: on the pinned
5.11.0, an empty app id does not fall back to the cached one.Affected code checklist
Checklist
Overview
Testing
Final pass