Conversation
…queue in getConstants Under TurboModules getConstants is invoked synchronously on the JS thread, so messagingConstantsDictionary called -[UIApplication isRegisteredForRemoteNotifications] off the main thread, which Main Thread Checker reports on every launch. Read that single value through RCTUnsafeExecuteOnMainQueueSync (runs inline when already on main), as NewArch-AD-9 prescribes, keeping requiresMainQueueSetup = NO.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Under the New Architecture,
getConstantson an iOS TurboModule is invoked synchronously on the JS thread.RNFBMessagingModule'smessagingConstantsDictionary(behindconstantsToExport/getConstants) reads-[UIApplication isRegisteredForRemoteNotifications], andUIApplicationis main-thread only. The module'srequiresMainQueueSetupreturnsNO, so nothing moves this read onto main.When the app runs under the Xcode debugger on a physical device, Main Thread Checker reports this on every launch:
The backtrace, on thread
com.facebook.react.runtime.JavaScript:Fix: read that one value through React Native's
RCTUnsafeExecuteOnMainQueueSync(from<React/RCTUtils.h>, which this file already imports). The helper runs the block inline when the caller is already on main. This is the explicit per-call dispatch that NewArch-AD-9 prescribes ("Any genuinely main-thread/UIKit work ingetConstants/init is dispatched explicitly to the main queue").initializeAppinRNFBAppModulealready uses the same pattern.requiresMainQueueSetupstaysNO, and theTARGET_IPHONE_SIMULATORbranch is unchanged.Scope notes:
isRegisteredForRemoteNotificationsreads, ingetToken,getAPNSTokenandregisterForRemoteNotifications, are untouched. This PR only covers thegetConstantspath that Main Thread Checker flagged.Related issues
None found. I searched for
isRegisteredForRemoteNotifications, "Main Thread Checker" and "UI API called on a background thread". The closest match is #507 (closed, 2017), which is about a different call,registerForRemoteNotifications.Release Summary
fix(messaging, ios): read
isRegisteredForRemoteNotificationson the main queue when building module constants, which stops the Main Thread Checker warning under the New Architecture.Checklist
AndroidiOSOther(macOS, web)e2etests added or updated inpackages/\*\*/e2ejesttests added or updated inpackages/\*\*/__tests__The change is iOS-only because Android has no equivalent main-thread read. There are no API or type changes: the constant has the same name, type and value.
Test Plan
yarn lint:ios:check) with the lockfile'sclang-format@1.8.0(clang-format 15.0.0):clang-format --style=Google -n -Werror packages/messaging/ios/RNFBMessaging/RNFBMessagingModule.mm. It passes.🔥
🤖 Generated with Claude Code