@@ -36,6 +36,7 @@ import { Code, FirestoreError } from '../util/error';
36
36
import * as log from '../util/log' ;
37
37
import { Rejecter , Resolver } from '../util/promise' ;
38
38
import { StringMap } from '../util/types' ;
39
+ import { isReactNative } from '../util/misc' ;
39
40
40
41
const LOG_TAG = 'Connection' ;
41
42
@@ -201,10 +202,6 @@ export class WebChannelConnection implements Connection {
201
202
// parameter.
202
203
httpSessionIdParam : 'gsessionid' ,
203
204
initMessageHeaders : { } ,
204
- // Send our custom headers as a '$httpHeaders=' url param to avoid CORS
205
- // preflight round-trip. This is formally defined here:
206
- // https://github.com/google/closure-library/blob/b0e1815b13fb92a46d7c9b3c30de5d6a396a3245/closure/goog/net/rpc/httpcors.js#L40
207
- httpHeadersOverwriteParam : '$httpHeaders' ,
208
205
messageUrlParams : {
209
206
// This param is used to improve routing and project isolation by the
210
207
// backend and must be included in every request.
@@ -215,6 +212,19 @@ export class WebChannelConnection implements Connection {
215
212
sendRawJson : true ,
216
213
supportsCrossDomainXhr : true
217
214
} ;
215
+
216
+ // Send our custom headers as a '$httpHeaders=' url param to avoid CORS
217
+ // preflight round-trip. This is formally defined here:
218
+ // https://github.com/google/closure-library/blob/b0e1815b13fb92a46d7c9b3c30de5d6a396a3245/closure/goog/net/rpc/httpcors.js#L40
219
+ //
220
+ // For some unclear reason (see
221
+ // https://github.com/firebase/firebase-js-sdk/issues/703), this breaks
222
+ // ReactNative and so we exclude it, which just means ReactNative may be
223
+ // subject to an extra network roundtrip for CORS preflight.
224
+ if ( ! isReactNative ( ) ) {
225
+ request [ 'httpHeadersOverwriteParam' ] = '$httpHeaders' ;
226
+ }
227
+
218
228
this . modifyHeadersForRequest ( request . initMessageHeaders , token ) ;
219
229
const url = urlParts . join ( '' ) ;
220
230
log . debug ( LOG_TAG , 'Creating WebChannel: ' + url + ' ' + request ) ;
0 commit comments