-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fixed opened push not getting called when app is terminated #145
Conversation
@@ -144,11 +144,8 @@ struct KlaviyoReducer: ReducerProtocol { | |||
} | |||
state.initalizationState = .initializing | |||
state.apiKey = apiKey | |||
// carry over pending events |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are now doing this before completing initialization since we know that in certain cases requests may be added state.pendingRequests
after this action has completed.
initialState.queue += queuedRequests | ||
// For any requests that get added between initilizing and initilized. | ||
// Ex: when the app is invoked from a push notification after being killed from the app switcher. | ||
let pendingRequests = state.pendingRequests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the line that actually fixes the issue. When we don't have this, the requests that are added to state.pendingRequests
after the initialization action were erased from state without enqueuing them.
@@ -441,4 +441,31 @@ class StateManagementTests: XCTestCase { | |||
try $0.enqueueRequest(request: .init(apiKey: XCTUnwrap($0.apiKey), endpoint: .createEvent(.init(data: .init(event: event, anonymousId: XCTUnwrap($0.anonymousId)))))) | |||
} | |||
} | |||
|
|||
func testEnqueueEventWhenInitilizingSendsEvent() async throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test to validate the solution works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome test!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a sort of second hand understanding of the root cause, and this fix makes sense to me based on that understanding!
Description
We were handling pending requests but when an app is terminated and launched again from a push notification open it triggers the open event and this open event is added to the pending requests since the SDK is not yet initialized (when the app is relaunched after terminating it's initialized again). However, between the SDK going from initializing to initialized the requests that were added to pending requests were ignored which is what was causing the opened push events from not getting enqueued and eventually sent out.
The fix was to just use the pending requests from state and enqueue each of those instead of using the state that was taken from the disk.
Check List
Manual Test Plan
Supporting Materials