Skip to content

Conversation

@hakonk
Copy link
Contributor

@hakonk hakonk commented May 27, 2021

This PR contains documentation for the proposed changes in this PR facebook/react-native#27701.

@netlify
Copy link

netlify bot commented May 27, 2021

✔️ Deploy Preview for react-native ready!

🔨 Explore the source changes: 58f1b9f

🔍 Inspect the deploy log: https://app.netlify.com/sites/react-native/deploys/611228ed5f74f50007ccaf93

😎 Browse the preview: https://deploy-preview-2629--react-native.netlify.app

@Simek Simek added the Wait on future Release This indicates a PR that updates the doc to match a future release. label Jul 20, 2021
Copy link
Collaborator

@Simek Simek left a comment

Choose a reason for hiding this comment

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

Hi @hakonk, thank you for the companion PR for the docs! 👍

However you have edited the docs for 0.64 release, when the changes should be part of next version:

Please move the new section to the suggested file above and then PR should be ready to be merged after the 0.65 release. 🙂

@hakonk
Copy link
Contributor Author

hakonk commented Jul 26, 2021

Hi @Simek ! I have moved the comment now 🙂

Copy link
Collaborator

@Simek Simek left a comment

Choose a reason for hiding this comment

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

@hakonk Thank you for the update! 👍

@taylorkline
Copy link

@hakonk If you don't mind, after applying the patch with patch-package from facebook/react-native@c299694:

diff --git a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.h b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.h
index 75b84eb..5a91bd0 100644
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.h
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.h
@@ -8,6 +8,11 @@
 #import <React/RCTInvalidating.h>
 #import <React/RCTURLRequestHandler.h>
 
+typedef NSURLSessionConfiguration* (^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);
 /**
  * This is the default RCTURLRequestHandler implementation for HTTP requests.
  */
diff --git a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
index 274f381..b500f5a 100644
--- a/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
+++ b/node_modules/react-native/Libraries/Network/RCTHTTPRequestHandler.mm
@@ -18,6 +18,12 @@
 
 @end
 
+static NSURLSessionConfigurationProvider urlSessionConfigurationProvider;
+
+void RCTSetCustomNSURLSessionConfigurationProvider(NSURLSessionConfigurationProvider provider) {
+  urlSessionConfigurationProvider = provider;
+}
+
 @implementation RCTHTTPRequestHandler
 {
   NSMapTable *_delegates;
@@ -75,14 +81,20 @@ RCT_EXPORT_MODULE()
     NSOperationQueue *callbackQueue = [NSOperationQueue new];
     callbackQueue.maxConcurrentOperationCount = 1;
     callbackQueue.underlyingQueue = [[_bridge networking] methodQueue];
-    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
-    // Set allowsCellularAccess to NO ONLY if key ReactNetworkForceWifiOnly exists AND its value is YES
-    if (useWifiOnly) {
-      configuration.allowsCellularAccess = ![useWifiOnly boolValue];
+    NSURLSessionConfiguration *configuration;
+    if (urlSessionConfigurationProvider) {
+      configuration = urlSessionConfigurationProvider();
+    } else {
+      configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
+      // Set allowsCellularAccess to NO ONLY if key ReactNetworkForceWifiOnly exists AND its value is YES
+      if (useWifiOnly) {
+        configuration.allowsCellularAccess = ![useWifiOnly boolValue];
+      }
+      [configuration setHTTPShouldSetCookies:YES];
+      [configuration setHTTPCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
+      [configuration setHTTPCookieStorage:[NSHTTPCookieStorage sharedHTTPCookieStorage]];
     }
-    [configuration setHTTPShouldSetCookies:YES];
-    [configuration setHTTPCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
-    [configuration setHTTPCookieStorage:[NSHTTPCookieStorage sharedHTTPCookieStorage]];
+    assert(configuration != nil);
     _session = [NSURLSession sessionWithConfiguration:configuration
                                              delegate:self
                                         delegateQueue:callbackQueue];

Should I be able to use the example in this PR after a simple yarn install and pod install?

As of right now, adding #import <React/RCTSetCustomNSURLSessionConfigurationProvider.h> results in 'React/RCTSetCustomNSURLSessionConfigurationProvider.h' file not found

@hakonk
Copy link
Contributor Author

hakonk commented Aug 10, 2021

Hi, @taylorkline! I believe the correct import should be #import <React/RCTHTTPRequestHandler.h>, as RCTSetCustomNSURLSessionConfigurationProvider is exposed via that file. That's probably worthy a comment though.

@taylorkline
Copy link

Thank you!

@Simek Simek merged commit 1c4f620 into facebook:master Aug 17, 2021
@hakonk
Copy link
Contributor Author

hakonk commented Aug 18, 2021

I'm confused. As pointed out here, the PR that this documentation describes the usage of will apparently not be included in 0.65. It will however be included in 0.66. @Simek

@Simek
Copy link
Collaborator

Simek commented Aug 18, 2021

@hakonk the 0.65 release has been published yester and docs for 0.65 has been cut and deployed.
After that the next docs became the future 0.66 release docs, so all the PRs with upcoming changes, which already landed in core repository can be merged in. 🙂

@hakonk
Copy link
Contributor Author

hakonk commented Aug 18, 2021

@Simek I found out it was included after all, please see this comment. Sorry for the confusion.

@Simek
Copy link
Collaborator

Simek commented Aug 18, 2021

@Simek I found out it was included after all, please see this comment. Sorry for the confusion.

Oh, that make sense, so we need to backport this PR to 0.65 docs, would you like to do this?

@hakonk
Copy link
Contributor Author

hakonk commented Aug 18, 2021

I willing to contribute, however, I'm unsure what kind of branching strategy you find appropriate to achieve this.

@Simek
Copy link
Collaborator

Simek commented Aug 18, 2021

All the "versioned" docs are located under website/versioned_docs directory and can be edited freely. You can read a bit more in the Readme:

This is how the Docusaurus works, we do not use separate branches for the docs releases to keep it simple and to allow an easy editing or backporting in the older docs. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Wait on future Release This indicates a PR that updates the doc to match a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants