Skip to content

fix: Rokt Callback should be Called on Main#683

Merged
BrandonStalnaker merged 1 commit intomainfrom
fix/Rokt-Callbacks-on-Main
Mar 25, 2026
Merged

fix: Rokt Callback should be Called on Main#683
BrandonStalnaker merged 1 commit intomainfrom
fix/Rokt-Callbacks-on-Main

Conversation

@BrandonStalnaker
Copy link
Copy Markdown
Collaborator

Background

  • Placement lifecycle callbacks (onLoad, onUnLoad, loading indicators, onEmbeddedSizeChange) are still invoked by Rokt’s native layer when work completes, and those invocations can occur on a background queue. Integrators often update Auto Layout, call layoutIfNeeded(), or publish to UI-bound streams from those callbacks, which is only safe on the main thread and can contribute to rare UIKit crashes or instability in production.

What Has Changed

  • Before forwarding to the kit, MPRokt now wraps a non-empty MPRoktEventCallback so each set handler runs on the main queue: synchronous execution when already on the main thread, otherwise dispatch_async to the main queue. onEmbeddedSizeChange copies the placement string before async dispatch so arguments stay valid.
  • Nil callbacks and callbacks with all properties nil are unchanged (still forwarded as nil where appropriate).
  • Public API documentation in MPRokt.h states that these callbacks are delivered on the main queue.
  • Unit tests were updated: the expanded selectPlacements test no longer asserts block identity (wrapping produces new blocks), and testSelectPlacementsMarshallsCallbacksToMainThread verifies that invoking the forwarded onLoad from a background queue runs the app’s handler on the main thread.

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

@BrandonStalnaker BrandonStalnaker self-assigned this Mar 24, 2026
@BrandonStalnaker BrandonStalnaker requested a review from a team as a code owner March 24, 2026 14:41
@cursor
Copy link
Copy Markdown

cursor bot commented Mar 24, 2026

PR Summary

Medium Risk
Changes the threading behavior of selectPlacements callbacks by wrapping and re-dispatching blocks, which could affect callback timing/order and surface latent race conditions, but is limited to Rokt placement lifecycle handlers.

Overview
Rokt placement lifecycle callbacks are now main-thread safe. MPRokt wraps any provided MPRoktEventCallback before forwarding to the Rokt kit so each non-nil handler (onLoad, onUnLoad, loading indicator callbacks, onEmbeddedSizeChange) executes synchronously on the main thread when already there, otherwise via dispatch_async to the main queue (copying onEmbeddedSizeChange args before dispatch).

Updates public header docs to guarantee main-queue delivery, and adjusts/adds unit tests to validate wrapping (block identity changes) and that invoking the forwarded callback from a background queue runs the original handler on the main thread.

Written by Cursor Bugbot for commit 8aa7e7c. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Copy Markdown

📦 SDK Size Impact Report

Measures how much the SDK adds to an app's size (with-SDK minus without-SDK).

Metric Target Branch This PR Change
App Bundle Impact 1.82 MB 1.82 MB +4 KB
Executable Impact 896 bytes 896 bytes +N/A
XCFramework Size 9.49 MB 9.50 MB +12 KB

➡️ SDK size impact change is minimal.

Raw measurements

Target branch (main):

{"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":1944,"with_sdk_executable_size_bytes":76360,"sdk_impact_kb":1860,"sdk_executable_impact_bytes":896,"xcframework_size_kb":9720}

This PR:

{"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":1948,"with_sdk_executable_size_bytes":76360,"sdk_impact_kb":1864,"sdk_executable_impact_bytes":896,"xcframework_size_kb":9732}

Copy link
Copy Markdown
Contributor

@nickolas-dimitrakas nickolas-dimitrakas left a comment

Choose a reason for hiding this comment

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

LGTM

@BrandonStalnaker BrandonStalnaker merged commit 21bd4c1 into main Mar 25, 2026
16 checks passed
@BrandonStalnaker BrandonStalnaker deleted the fix/Rokt-Callbacks-on-Main branch March 25, 2026 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants