From c7429b0e97b400a88158f73d2250f8d5f16593cf Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 20 Oct 2026 17:25:20 -0700 Subject: [PATCH] Fix nullability annotations in iOS networking headers (#59240) Summary: Importing `RCTMultipartDataTask.h` and `RCTHTTPRequestHandler.h` produces nullability-completeness warnings because the headers mix annotated return values with unannotated pointers and blocks. Complete the annotations with `NS_ASSUME_NONNULL`, keeping optional configuration providers, interceptors, progress handlers and multipart callback payloads nullable. This matches the existing implementations, including clearing an interceptor with `nil` and reporting a failed multipart response without headers or content. ## Changelog: [IOS] [FIXED] - Fix missing nullability annotations in networking headers. Pull Request resolved: https://github.com/react/react-native/pull/59240 Test Plan: - Compiled a translation unit importing both headers with the Xcode 27.1 iOS Simulator SDK, ARC, blocks and `-Werror`. Passed in Objective-C and Objective-C++ modes. It also exercises clearing all three providers/interceptors with `nil`, returning `nil` from each interceptor, nullable multipart callback payloads and an absent progress callback. - The same header import on the original revision fails with nine `-Wnullability-completeness` errors. - Compiled `RCTMultipartDataTask.m` with `-fsyntax-only -Werror=nullability-completeness` against the same SDK. Passed. - Checked both changed headers with the repository's pinned clang-format 21.1.2 (`--dry-run --Werror`) and ran `git diff --check`. Passed. A full RNTester build was not run for this header-only change. Snapshot completion (local update): - Added the four generated ReactApple API snapshots from the CI artifact for PR head `151876277233befdbe7c0d9818039aa08ad15d1c`; verified the artifact SHA-256 against GitHub metadata. Imported headers and all prior snapshots match that revision. No header implementation or dependency changes. - The repository `validate_snapshots` comparison passes for all 12 generated views. `arc lint -a` reports no lint issues. - Full local `buck2 run fbsource//xplat/js/react-native-github/scripts/cxx-api:api-snapshot` could not regenerate: the existing codegen environment lacks `tinyglobby`. The updated files are exact generated CI output, not hand-edited snapshots. Reviewed By: christophpurrer Differential Revision: D126472293 Pulled By: javache fbshipit-source-id: 0c4f87e4d6f8c57f89f9e914d1c44a60802df1b6 --- .../Libraries/Network/RCTHTTPRequestHandler.h | 8 ++++++-- .../React/Base/RCTMultipartDataTask.h | 15 ++++++++++----- .../cxx-api/api-snapshots/ReactAppleDebugCxx.api | 2 +- .../api-snapshots/ReactAppleFrameworksCxx.api | 2 +- .../api-snapshots/ReactAppleNewarchCxx.api | 2 +- .../api-snapshots/ReactAppleReleaseCxx.api | 2 +- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/react-native/Libraries/Network/RCTHTTPRequestHandler.h b/packages/react-native/Libraries/Network/RCTHTTPRequestHandler.h index 15d986e529c..7c86b27bae0 100644 --- a/packages/react-native/Libraries/Network/RCTHTTPRequestHandler.h +++ b/packages/react-native/Libraries/Network/RCTHTTPRequestHandler.h @@ -8,12 +8,14 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + typedef NSURLSessionConfiguration *_Nullable (^NSURLSessionConfigurationProvider)(void); /** * The block provided via this function will provide the NSURLSessionConfiguration for all HTTP requests made by the * app. */ -RCT_EXTERN void RCTSetCustomNSURLSessionConfigurationProvider(NSURLSessionConfigurationProvider /*provider*/); +RCT_EXTERN void RCTSetCustomNSURLSessionConfigurationProvider(NSURLSessionConfigurationProvider _Nullable /*provider*/); typedef NSURLRequest *_Nullable (^RCTHTTPRequestInterceptor)(NSURLRequest *request); /** @@ -21,7 +23,7 @@ typedef NSURLRequest *_Nullable (^RCTHTTPRequestInterceptor)(NSURLRequest *reque * they are sent. Return a modified request to override, or nil to use the * original request unchanged. */ -RCT_EXTERN void RCTSetCustomHTTPRequestInterceptor(RCTHTTPRequestInterceptor /*interceptor*/); +RCT_EXTERN void RCTSetCustomHTTPRequestInterceptor(RCTHTTPRequestInterceptor _Nullable /*interceptor*/); /** * This is the default RCTURLRequestHandler implementation for HTTP requests. @@ -29,3 +31,5 @@ RCT_EXTERN void RCTSetCustomHTTPRequestInterceptor(RCTHTTPRequestInterceptor /*i @interface RCTHTTPRequestHandler : NSObject @end + +NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/Base/RCTMultipartDataTask.h b/packages/react-native/React/Base/RCTMultipartDataTask.h index 9b94a260a90..b161bf33b32 100644 --- a/packages/react-native/React/Base/RCTMultipartDataTask.h +++ b/packages/react-native/React/Base/RCTMultipartDataTask.h @@ -10,11 +10,13 @@ #import #import +NS_ASSUME_NONNULL_BEGIN + typedef void (^RCTMultipartDataTaskCallback)( NSInteger statusCode, - NSDictionary *headers, - NSData *content, - NSError *error, + NSDictionary *_Nullable headers, + NSData *_Nullable content, + NSError *_Nullable error, BOOL done); typedef NSURLRequest *_Nullable (^RCTMultipartDataTaskRequestInterceptor)(NSURLRequest *request); @@ -23,14 +25,17 @@ typedef NSURLRequest *_Nullable (^RCTMultipartDataTaskRequestInterceptor)(NSURLR * requests before they are sent. Return a modified request to override, or nil * to use the original request unchanged. */ -RCT_EXTERN void RCTSetCustomMultipartDataTaskRequestInterceptor(RCTMultipartDataTaskRequestInterceptor /*interceptor*/); +RCT_EXTERN void RCTSetCustomMultipartDataTaskRequestInterceptor( + RCTMultipartDataTaskRequestInterceptor _Nullable /*interceptor*/); @interface RCTMultipartDataTask : NSObject - (instancetype)initWithURL:(NSURL *)url partHandler:(RCTMultipartDataTaskCallback)partHandler - progressHandler:(RCTMultipartProgressCallback)progressHandler; + progressHandler:(nullable RCTMultipartProgressCallback)progressHandler; - (void)startTask; @end + +NS_ASSUME_NONNULL_END diff --git a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api index 483efc9b46d..cd7cd6ba81f 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api @@ -1410,7 +1410,7 @@ interface RCTMountingManager : public NSObject { } interface RCTMultipartDataTask : public NSObject { - public virtual instancetype initWithURL:partHandler:progressHandler:(NSURL* url, RCTMultipartDataTaskCallback partHandler, RCTMultipartProgressCallback progressHandler); + public virtual instancetype initWithURL:partHandler:progressHandler:(NSURL* url, RCTMultipartDataTaskCallback partHandler, _Nullable RCTMultipartProgressCallback progressHandler); public virtual void startTask(); } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api index b1f98e0f87f..a21ebf06823 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api @@ -1453,7 +1453,7 @@ interface RCTMountingManager : public NSObject { } interface RCTMultipartDataTask : public NSObject { - public virtual instancetype initWithURL:partHandler:progressHandler:(NSURL* url, RCTMultipartDataTaskCallback partHandler, RCTMultipartProgressCallback progressHandler); + public virtual instancetype initWithURL:partHandler:progressHandler:(NSURL* url, RCTMultipartDataTaskCallback partHandler, _Nullable RCTMultipartProgressCallback progressHandler); public virtual void startTask(); } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api index e9ea4c1f053..aab9559c8f3 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api @@ -1410,7 +1410,7 @@ interface RCTMountingManager : public NSObject { } interface RCTMultipartDataTask : public NSObject { - public virtual instancetype initWithURL:partHandler:progressHandler:(NSURL* url, RCTMultipartDataTaskCallback partHandler, RCTMultipartProgressCallback progressHandler); + public virtual instancetype initWithURL:partHandler:progressHandler:(NSURL* url, RCTMultipartDataTaskCallback partHandler, _Nullable RCTMultipartProgressCallback progressHandler); public virtual void startTask(); } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api index 57197975be4..47e70d959eb 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api @@ -1410,7 +1410,7 @@ interface RCTMountingManager : public NSObject { } interface RCTMultipartDataTask : public NSObject { - public virtual instancetype initWithURL:partHandler:progressHandler:(NSURL* url, RCTMultipartDataTaskCallback partHandler, RCTMultipartProgressCallback progressHandler); + public virtual instancetype initWithURL:partHandler:progressHandler:(NSURL* url, RCTMultipartDataTaskCallback partHandler, _Nullable RCTMultipartProgressCallback progressHandler); public virtual void startTask(); }