expo / expo/browser-polyfill

Firebase JS SDK breaks when importing @expo/browser-polyfill

Open
#35 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
69
Forks
26
PR merge metrics
No merged PRs in 30d

Description

This happened some time ago:
https://github.com/expo/expo-three/issues/53
https://github.com/expo/browser-polyfill/issues/2

and comes back again! @EvanBacon

## WTR

Basically, one need to:
1. Import `@expo/browser-polyfill` somewhere deep in the jungle of packages
2. sign in using Firebase JS SDK
3. observe some Firestore entity using `onSnapshot`, then unsubscribe (gracefully)
4. sign out

This way is a 100% repro, but I have seen other random cases when that happened during Firebase sign in session.

Libraries

```json
"@expo/browser-polyfill": "^0.1.0",
"expo": "~37.0.3",
"firebase": "7.9.0",
```

Code snippet to reproduce

```typescript

import '@expo/browser-polyfill';

import firebase from 'firebase/app';

import 'firebase/auth';
import 'firebase/firestore';

const validFirebaseConfig = {
/* ... */
};

export async function doFirebaseTest() {
// Initialize Firebase App
const instance = firebase.initializeApp(validFirebaseConfig);

// Do a simple log in
console.log('logging in...');
if (!instance.auth().currentUser) {
await instance.auth().signInWithEmailAndPassword('ivan@zajno.com', '123456');
}

const uid = instance.auth().currentUser?.uid;

// IMPORTANT: Add onSnapshot observer on any Firestore entity
// only with this it will break
console.log('subscribing to the user in Firestore...');
const unsub1 = instance.firestore().doc(`users/${uid}`).onSnapshot(snapshot => {
console.log('Got the User!!!', snapshot.data());
});

// just wait a bit to avoid race conditions
console.log('waiting for 2 seconds...');
setTimeout(async () => {
unsub1();

console.log('logging out...');
// HERE you will see crash on Android or error RedBox for iOS simulator / Android emulator
await instance.auth().signOut();

console.log('completed!!!');
}, 2000)
}

```

## Actual Result

### iOS
Device – nothing bad happens that a user can see
Simulator:

```
No suitable URL request handler found for (null)

-[ABI37_0_0RCTNetworking networkTaskWithRequest:completionBlock:]
ABI37_0_0RCTNetworking.mm:654
-[ABI37_0_0RCTImageLoader _loadURLRequest:progressBlock:completionBlock:]
__127-[ABI37_0_0RCTImageLoader _loadImageOrDataWithURLRequest:size:scale:resizeMode:progressBlock:partialLoadBlock:completionBlock:]_block_invoke.183
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_lane_serial_drain
_dispatch_lane_invoke
_dispatch_workloop_worker_thread
_pthread_wqthread
start_wqthread

```

Screenshot

![image](https://user-images.githubusercontent.com/15375564/80193698-fb840f00-8621-11ea-83d3-d881d774463b.png)

### Android feels much worse about it

Device – **crash/reload**
Virtual Device – app hangs with the error:

```
abi37_0_0.com.facebook.react.bridge.ReadableNativeMap cannot be cast to java.lang.String
```

Screenshot

![image](https://user-images.githubusercontent.com/15375564/80194293-d512a380-8622-11ea-9208-3611816fe3dc.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.