Skip to content

Commit 12e4a57

Browse files
okwasniewskifacebook-github-bot
authored andcommitted
feat: add nullable annotations to RCTBundleURLProvider (#42293)
Summary: This PR adds nullable annotations to `RCTBundleURLProvider` also allowing to return optional (the default that will be returned when metro is not running). Not having this may lead to crashes because Swift will try to unwrap optional with nil when metro is not running. ## Changelog: [iOS] [Added] - add nullable annotations to RCTBundleURLProvider Pull Request resolved: #42293 Test Plan: CI Green Reviewed By: sammy-SC Differential Revision: D52797676 Pulled By: cipolleschi fbshipit-source-id: 98b4f99aa71828f5397276d22f35d24e48657dc8
1 parent 50bd9e3 commit 12e4a57

3 files changed

Lines changed: 36 additions & 31 deletions

File tree

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN
158158
- (BOOL)bridgelessEnabled;
159159

160160
/// Return the bundle URL for the main bundle.
161-
- (NSURL *)bundleURL;
161+
- (NSURL *__nullable)bundleURL;
162162

163163
@end
164164

packages/react-native/React/Base/RCTBridgeDelegate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
2020
* When running from a locally bundled JS file, this should be a `file://` url
2121
* pointing to a path inside the app resources, e.g. `file://.../main.jsbundle`.
2222
*/
23-
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge;
23+
- (NSURL *__nullable)sourceURLForBridge:(RCTBridge *)bridge;
2424

2525
@optional
2626

packages/react-native/React/Base/RCTBundleURLProvider.h

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#import "RCTDefines.h"
1111

12-
RCT_EXTERN NSString *const RCTBundleURLProviderUpdatedNotification;
12+
RCT_EXTERN NSString *_Nonnull const RCTBundleURLProviderUpdatedNotification;
1313
RCT_EXTERN const NSUInteger kRCTBundleURLProviderDefaultPort;
1414

1515
#if RCT_DEV_MENU | RCT_PACKAGER_LOADING_FUNCTIONALITY
@@ -22,6 +22,8 @@ RCT_EXTERN const NSUInteger kRCTBundleURLProviderDefaultPort;
2222
RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
2323
#endif
2424

25+
NS_ASSUME_NONNULL_BEGIN
26+
2527
@interface RCTBundleURLProvider : NSObject
2628

2729
/**
@@ -52,52 +54,53 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
5254
* The port is optional, if not specified, kRCTBundleURLProviderDefaultPort will be used
5355
* The scheme is also optional, if not specified, a default http protocol will be used
5456
*/
55-
+ (BOOL)isPackagerRunning:(NSString *)hostPort scheme:(NSString *)scheme;
57+
+ (BOOL)isPackagerRunning:(NSString *)hostPort scheme:(NSString *__nullable)scheme;
5658

5759
/**
5860
* Returns the jsBundleURL for a given bundle entrypoint and
5961
* the fallback offline JS bundle if the packager is not running.
6062
*/
61-
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackURLProvider:(NSURL * (^)(void))fallbackURLProvider;
63+
- (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot
64+
fallbackURLProvider:(NSURL *__nullable (^)(void))fallbackURLProvider;
6265

6366
/**
6467
* Returns the jsBundleURL for a given split bundle entrypoint in development
6568
*/
66-
- (NSURL *)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot;
69+
- (NSURL *__nullable)jsBundleURLForSplitBundleRoot:(NSString *)bundleRoot;
6770

6871
/**
6972
* Returns the jsBundleURL for a given bundle entrypoint and
7073
* the fallback offline JS bundle if the packager is not running.
7174
* if extension is nil, "jsbundle" will be used.
7275
*/
73-
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackExtension:(NSString *)extension;
76+
- (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot fallbackExtension:(NSString *__nullable)extension;
7477

7578
/**
7679
* Returns the jsBundleURL for a given bundle entrypoint and
7780
* the fallback offline JS bundle if the packager is not running.
7881
*/
79-
- (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot;
82+
- (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot;
8083

8184
/**
8285
* Returns the jsBundleURL for a given bundle entrypoint and
8386
* the fallback offline JS bundle. If extension is nil,
8487
* "jsbundle" will be used.
8588
*/
86-
- (NSURL *)jsBundleURLForFallbackExtension:(NSString *)extension;
89+
- (NSURL *__nullable)jsBundleURLForFallbackExtension:(NSString *__nullable)extension;
8790

8891
/**
8992
* Returns the resourceURL for a given bundle entrypoint and
9093
* the fallback offline resource file if the packager is not running.
9194
*/
92-
- (NSURL *)resourceURLForResourceRoot:(NSString *)root
93-
resourceName:(NSString *)name
94-
resourceExtension:(NSString *)extension
95-
offlineBundle:(NSBundle *)offlineBundle;
95+
- (NSURL *__nullable)resourceURLForResourceRoot:(NSString *)root
96+
resourceName:(NSString *)name
97+
resourceExtension:(NSString *)extension
98+
offlineBundle:(NSBundle *)offlineBundle;
9699

97100
/**
98101
* The IP address or hostname of the packager.
99102
*/
100-
@property (nonatomic, copy) NSString *jsLocation;
103+
@property (nonatomic, copy, nullable) NSString *jsLocation;
101104

102105
@property (nonatomic, assign) BOOL enableMinification;
103106
@property (nonatomic, assign) BOOL enableDev;
@@ -124,29 +127,29 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
124127
* - runModule: When true, will run the main module after defining all modules. This is used in the main bundle but not
125128
* in split bundles.
126129
*/
127-
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
128-
packagerHost:(NSString *)packagerHost
129-
enableDev:(BOOL)enableDev
130-
enableMinification:(BOOL)enableMinification
131-
inlineSourceMap:(BOOL)inlineSourceMap;
132-
133-
+ (NSURL *)jsBundleURLForBundleRoot:(NSString *)bundleRoot
134-
packagerHost:(NSString *)packagerHost
135-
packagerScheme:(NSString *)scheme
136-
enableDev:(BOOL)enableDev
137-
enableMinification:(BOOL)enableMinification
138-
inlineSourceMap:(BOOL)inlineSourceMap
139-
modulesOnly:(BOOL)modulesOnly
140-
runModule:(BOOL)runModule;
130+
+ (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot
131+
packagerHost:(NSString *)packagerHost
132+
enableDev:(BOOL)enableDev
133+
enableMinification:(BOOL)enableMinification
134+
inlineSourceMap:(BOOL)inlineSourceMap;
135+
136+
+ (NSURL *__nullable)jsBundleURLForBundleRoot:(NSString *)bundleRoot
137+
packagerHost:(NSString *)packagerHost
138+
packagerScheme:(NSString *__nullable)scheme
139+
enableDev:(BOOL)enableDev
140+
enableMinification:(BOOL)enableMinification
141+
inlineSourceMap:(BOOL)inlineSourceMap
142+
modulesOnly:(BOOL)modulesOnly
143+
runModule:(BOOL)runModule;
141144
/**
142145
* Given a hostname for the packager and a resource path (including "/"), return the URL to the resource.
143146
* In general, please use the instance method to decide if the packager is running and fallback to the pre-packaged
144147
* resource if it is not: -resourceURLForResourceRoot:resourceName:resourceExtension:offlineBundle:
145148
*/
146149
+ (NSURL *)resourceURLForResourcePath:(NSString *)path
147150
packagerHost:(NSString *)packagerHost
148-
scheme:(NSString *)scheme
149-
query:(NSString *)query
151+
scheme:(NSString *__nullable)scheme
152+
query:(NSString *__nullable)query
150153
__deprecated_msg("Use version with queryItems parameter instead");
151154

152155
/**
@@ -157,6 +160,8 @@ RCT_EXTERN void RCTBundleURLProviderAllowPackagerServerAccess(BOOL allowed);
157160
+ (NSURL *)resourceURLForResourcePath:(NSString *)path
158161
packagerHost:(NSString *)packagerHost
159162
scheme:(NSString *)scheme
160-
queryItems:(NSArray<NSURLQueryItem *> *)queryItems;
163+
queryItems:(NSArray<NSURLQueryItem *> *__nullable)queryItems;
161164

162165
@end
166+
167+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)