Skip to content

React Native build breaks Writes #3243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
djoiiwalraven opened this issue Jun 20, 2020 · 10 comments · Fixed by #3244
Closed

React Native build breaks Writes #3243

djoiiwalraven opened this issue Jun 20, 2020 · 10 comments · Fixed by #3244
Assignees

Comments

@djoiiwalraven
Copy link

#2929 # [REQUIRED] Describe your environment

  • Operating System version: MacOS Catalina 10.15.4
  • Browser version: Google Chrome 83.0.4103.106 (Official Build) (64-bit)
  • Firebase SDK version: firebase-js-sdk 7.15.3
  • Firebase Product: Firestore

Describe problem:

Everywhere I call firebase.firestore.collection('...').add({...});
I get a warning message:

[Unhandled promise rejection: FirebaseError: invalid stream token]
* [native code]:null in construct
- node_modules/@babel/runtime/helpers/construct.js:19:26 in _construct
- node_modules/@babel/runtime/helpers/wrapNativeSuper.js:26:23 in Wrapper
* [native code]:null in construct
- node_modules/@firebase/auth/dist/auth.js:418:106 in <anonymous>
- node_modules/@firebase/auth/dist/auth.js:420:391 in <anonymous>
- node_modules/@firebase/firestore/dist/index.rn.esm2017.js:15027:6 in bE
* http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:157721:16 in <unknown>
- node_modules/@firebase/webchannel-wrapper/dist/index.js:141:11 in <anonymous>
- node_modules/@firebase/webchannel-wrapper/dist/index.js:126:32 in Ca
- node_modules/@firebase/webchannel-wrapper/dist/index.js:1052:12 in Ec
- node_modules/@firebase/webchannel-wrapper/dist/index.js:435:50 in g.Ia
* http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:159122:20 in qc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:375:27 in ub
- node_modules/@firebase/webchannel-wrapper/dist/index.js:357:58 in g.dispatchEvent
- node_modules/@firebase/webchannel-wrapper/dist/index.js:141:11 in <anonymous>
- node_modules/@firebase/webchannel-wrapper/dist/index.js:126:32 in Ca
- node_modules/@firebase/webchannel-wrapper/dist/index.js:759:29 in Nc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:755:13 in Mc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:751:26 in Mc
* [native code]:null in <unknown>
- node_modules/event-target-shim/dist/event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:566:23 in setReadyState
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:350:23 in __didReceiveIncrementalData
- node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12 in emit
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:436:47 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:26 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue

Steps/Code to reproduce:

const firebase = require('firebase/app');
require('firebase/auth');
require('firebase/firestore');

const FIRE_DB_CONFIG = {...};

const config = {
  apiKey: FIRE_DB_CONFIG.API_KEY,
  authDomain: FIRE_DB_CONFIG.AUTH_DOMAIN,
  databaseURL: FIRE_DB_CONFIG.DATABASE_URL,
  projectId: FIRE_DB_CONFIG.PROJECT_ID,
  storageBucket: FIRE_DB_CONFIG.STORAGE_BUCKET,
  messagingSenderId: FIRE_DB_CONFIG.MESSAGING_SENDER_ID,
  appId: FIRE_DB_CONFIG.APP_ID,
  //measurementId: FIRE_DB_CONFIG.MEASUREMEANT_ID
}

firebase.initializeApp(config);

export const firestore = firebase.firestore();

const fire = () => {
  try {
    firestore.collection("users").add({
        first: "Ada",
        last: "Lovelace",
        born: 1815
    })
  } catch (e) {
    console.log(e);
  }
};

fire();
export default firebase;

This will also happen if I import firestore elsewhere and call: firestore.collection(...).add({...});

package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@react-native-community/masked-view": "0.1.6",
    "@react-navigation/bottom-tabs": "^5.5.2",
    "@react-navigation/native": "^5.5.1",
    "expo": "~37.0.3",
    "expo-google-app-auth": "^8.1.0",
    "firebase": "^7.15.3",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
    "react-native-animatable": "^1.3.3",
    "react-native-gesture-handler": "~1.6.0",
    "react-native-reanimated": "~1.7.0",
    "react-native-safe-area-context": "0.7.3",
    "react-native-screens": "~2.2.0",
    "react-native-shadow": "^1.2.2",
    "react-native-svg": "^12.1.0",
    "react-native-web": "~0.11.7",
    "react-redux": "^7.2.0",
    "redux": "^4.0.5"
  },
  "devDependencies": {
    "babel-preset-expo": "~8.1.0",
    "@babel/core": "^7.8.6"
  },
  "private": true
}
@var-const
Copy link
Contributor

Thanks for reporting the issue. I couldn't reproduce it running the code snippet you provided, but I also couldn't replicate your whole environment (I'm getting errors trying to run the web script, which I presume is what you're using). Which expo command are you using? Would it be possible for you to provide a full working repro project? Also, could you please enable debug logging and post the resulting logs?

@djoiiwalraven
Copy link
Author

djoiiwalraven commented Jun 20, 2020

I used expo init to create my project.

I am not running the web-script since I also get errors using that. But I intended my project to be native only anyway. I am using the expo app on iPhone 11 pro simulator, software version: 13.5 & the expo app on realme X2 android version 10. On both devices I get the same warning and also the same debug from firestore, after enabling debug logging.

Resulting Logs

this has been edited, I forgot to turn on the function that actually caused the error..

Running application on iPhone 11 Pro Max.
~ Log() Refreshed ~
[2020-06-20T03:08:08.140Z]  @firebase/firestore: Firestore (7.15.2): FirestoreClient Initializing. user= ygidvk76QVWKlH9I0GcDtasH1T63
login sucess!
[2020-06-20T03:08:08.231Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get next mutation batch
[2020-06-20T03:08:08.242Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Locally write mutations
[2020-06-20T03:08:08.248Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: notifyLocalViewChanges
[2020-06-20T03:08:08.254Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get next mutation batch
[2020-06-20T03:08:08.257Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get next mutation batch
[2020-06-20T03:08:08.263Z]  @firebase/firestore: Firestore (7.15.2): Connection Creating WebChannel: https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel [object Object]
[2020-06-20T03:08:08.276Z]  @firebase/firestore: Firestore (7.15.2): Connection Opening WebChannel transport.
[2020-06-20T03:08:08.280Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"database":"projects/xculture-69acd/databases/(default)"}
[2020-06-20T03:08:08.430Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel transport opened.
[2020-06-20T03:08:08.457Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"streamId":"0","streamToken":"GRBoQgKB9LW1"}
[2020-06-20T03:08:08.461Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"streamToken":"GRBoQgLhtLXlgIA=","writes":[{"update":{"name":"projects/xculture-69acd/databases/(default)/documents/users/S4H7OMUDROEUMAA2kDdo","fields":{"first":{"stringValue":"Ada"},"last":{"stringValue":"Lovelace"},"born":{"integerValue":"1815"}}}}]}
[2020-06-20T03:08:08.496Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received error: {"code":400,"message":"invalid stream token","status":"INVALID_ARGUMENT"}
[2020-06-20T03:08:08.502Z]  @firebase/firestore: Firestore (7.15.2): PersistentStream close with error: FirebaseError: [code=invalid-argument]: invalid stream token
[2020-06-20T03:08:08.505Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Reject batch
[2020-06-20T03:08:08.518Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: notifyLocalViewChanges
[2020-06-20T03:08:08.541Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get next mutation batch

invalid stream token
* [native code]:null in construct
- node_modules/@babel/runtime/helpers/construct.js:19:26 in _construct
- node_modules/@babel/runtime/helpers/wrapNativeSuper.js:26:23 in Wrapper
* [native code]:null in construct
- node_modules/@firebase/auth/dist/auth.js:418:106 in <anonymous>
- node_modules/@firebase/auth/dist/auth.js:420:391 in <anonymous>
- node_modules/@firebase/firestore/dist/index.rn.esm2017.js:15027:6 in bE
* http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:157633:16 in <unknown>
- node_modules/@firebase/webchannel-wrapper/dist/index.js:141:11 in <anonymous>
- node_modules/@firebase/webchannel-wrapper/dist/index.js:126:32 in Ca
- node_modules/@firebase/webchannel-wrapper/dist/index.js:1052:12 in Ec
- node_modules/@firebase/webchannel-wrapper/dist/index.js:435:50 in g.Ia
* http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:159034:20 in qc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:375:27 in ub
- node_modules/@firebase/webchannel-wrapper/dist/index.js:357:58 in g.dispatchEvent
- node_modules/@firebase/webchannel-wrapper/dist/index.js:141:11 in <anonymous>
- node_modules/@firebase/webchannel-wrapper/dist/index.js:126:32 in Ca
- node_modules/@firebase/webchannel-wrapper/dist/index.js:759:29 in Nc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:755:13 in Mc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:751:26 in Mc
* [native code]:null in <unknown>
- node_modules/event-target-shim/dist/event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:566:23 in setReadyState
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:350:23 in __didReceiveIncrementalData
- node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12 in emit
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:436:47 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:26 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue

Repro

I'm not sure if this is what you mean with repro project nor if you can view my project, I'm new to using GitHub.
https://github.com/djoiiwalraven/xCulture
...
What I also find strange is that it shows version 7.15.2 even tho in my package.json I have version 7.15.3. I I installed the new version when it came out, which fixed the previous issue I had: #3240

@djoiiwalraven
Copy link
Author

I would also like to mention, I used the same approach on a different app I was making a few months ago, in this app everything was working perfectly with firestore. But it broke after updating the firebase sdk. Now that I worked on this new app I pretty much re used the previous approach. I just tested the latest firebase sdk 7.15.3 in this app. And I get the same warning message. Also I am not able to add data anymore to my firestore. I was able to receive data from the firestore.

Here is the log from where everything is still working fine

[2020-06-20T03:23:47.940Z]  @firebase/firestore: Firestore (7.15.2): FirestoreClient Initializing. user= hFXB2sBetFeip9lSNlBITj2eVYX2
[2020-06-20T03:23:47.970Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get next mutation batch
[2020-06-20T03:23:47.982Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Allocate target
[2020-06-20T03:23:47.987Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Execute query
[2020-06-20T03:23:47.990Z]  @firebase/firestore: Firestore (7.15.2): IndexFreeQueryEngine Using full collection scan to execute query: Query(target=Target(eventCards, orderBy: [__name__ (asc)]); limitType=F)
[2020-06-20T03:23:48.002Z]  @firebase/firestore: Firestore (7.15.2): Connection Creating WebChannel: https://firestore.googleapis.com/google.firestore.v1.Firestore/Listen/channel [object Object]
[2020-06-20T03:23:48.013Z]  @firebase/firestore: Firestore (7.15.2): Connection Opening WebChannel transport.
[2020-06-20T03:23:48.017Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"database":"projects/waarisdatfeestje-883cf/databases/(default)","addTarget":{"query":{"structuredQuery":{"from":[{"collectionId":"eventCards"}],"orderBy":[{"field":{"fieldPath":"__name__"},"direction":"ASCENDING"}]},"parent":"projects/waarisdatfeestje-883cf/databases/(default)/documents"},"targetId":2}}
[2020-06-20T03:23:48.148Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel transport opened.
[2020-06-20T03:23:48.212Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"targetChange":{"targetChangeType":"ADD","targetIds":[2]}}
[2020-06-20T03:23:48.242Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"documentChange":{"document":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/4ITbJxrQ1FF45llKuLRG","fields":{"event":{"mapValue":{"fields":{"titel":{"stringValue":"Stille Disco"},"likes":{"integerValue":"0"},"location":{"stringValue":"Hengelo"},"date":{"timestampValue":"2020-06-12T14:42:42Z"},"tickets":{"arrayValue":{}},"promo":{"stringValue":""},"info":{"stringValue":""}}}}},"createTime":"2020-02-26T13:56:58.491924Z","updateTime":"2020-02-26T13:56:58.491924Z"},"targetIds":[2]}}
[2020-06-20T03:23:48.249Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"documentChange":{"document":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/5rmgsUcevp40mO8FWEJN","fields":{"event":{"mapValue":{"fields":{"promo":{"stringValue":""},"tickets":{"arrayValue":{}},"location":{"stringValue":"Enschede"},"date":{"timestampValue":"2020-06-12T14:42:42Z"},"titel":{"stringValue":"Stille Disco"},"likes":{"integerValue":"0"},"info":{"stringValue":""}}}}},"createTime":"2020-02-26T13:56:10.780745Z","updateTime":"2020-02-26T13:56:10.780745Z"},"targetIds":[2]}}
[2020-06-20T03:23:48.251Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"documentChange":{"document":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/7OSKI4nfIYzO1pHEsP4U","fields":{"event":{"mapValue":{"fields":{"promo":{"stringValue":""},"location":{"stringValue":"Enschede"},"info":{"stringValue":""},"tickets":{"arrayValue":{}},"date":{"timestampValue":"2020-06-12T14:42:42Z"},"titel":{"stringValue":"Koningsdag"},"likes":{"integerValue":"0"}}}}},"createTime":"2020-02-26T13:54:14.459798Z","updateTime":"2020-02-26T13:54:14.459798Z"},"targetIds":[2]}}
[2020-06-20T03:23:48.262Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"documentChange":{"document":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/CFG62uIZGeZtX00Lto8r","fields":{"event":{"mapValue":{"fields":{"date":{"timestampValue":"2020-06-12T14:42:42Z"},"tickets":{"arrayValue":{}},"promo":{"stringValue":""},"titel":{"stringValue":"Koningsdag"},"location":{"stringValue":"Hengelo"},"likes":{"integerValue":"0"},"info":{"stringValue":""}}}}},"createTime":"2020-02-26T13:54:20.023482Z","updateTime":"2020-02-26T13:54:20.023482Z"},"targetIds":[2]}}
[2020-06-20T03:23:48.268Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"documentChange":{"document":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/T5TpM6QRAe315WhpBX4B","fields":{"event":{"mapValue":{"fields":{"promo":{"stringValue":""},"tickets":{"arrayValue":{}},"location":{"stringValue":"Enschede"},"date":{"timestampValue":"2020-06-12T14:42:42Z"},"titel":{"stringValue":"Beerpong"},"info":{"stringValue":""},"likes":{"integerValue":"0"}}}}},"createTime":"2020-02-26T13:54:33.891365Z","updateTime":"2020-02-26T13:54:33.891365Z"},"targetIds":[2]}}
[2020-06-20T03:23:48.270Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"documentChange":{"document":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/eduVgOoHXxgOvfcFgqGZ","fields":{"event":{"mapValue":{"fields":{"info":{"stringValue":""},"titel":{"stringValue":"Carnival"},"promo":{"stringValue":""},"tickets":{"arrayValue":{}},"date":{"timestampValue":"2020-06-12T14:42:42Z"},"likes":{"integerValue":"0"},"location":{"stringValue":"Losser"}}}}},"createTime":"2020-02-26T13:55:10.892182Z","updateTime":"2020-02-26T13:55:10.892182Z"},"targetIds":[2]}}
[2020-06-20T03:23:48.272Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"documentChange":{"document":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/p10IM513gvc5m6swGRGu","fields":{"event":{"mapValue":{"fields":{"location":{"stringValue":"Brabant"},"titel":{"stringValue":"Carnival"},"likes":{"integerValue":"0"},"tickets":{"arrayValue":{}},"date":{"timestampValue":"2020-06-12T14:42:42Z"},"info":{"stringValue":""},"promo":{"stringValue":""}}}}},"createTime":"2020-02-26T13:55:05.542831Z","updateTime":"2020-02-26T13:55:05.542831Z"},"targetIds":[2]}}
[2020-06-20T03:23:48.274Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"documentChange":{"document":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/qAnOuI1QGQlPhv839DIQ","fields":{"event":{"mapValue":{"fields":{"date":{"timestampValue":"2020-06-12T14:42:42Z"},"promo":{"stringValue":""},"info":{"stringValue":""},"likes":{"integerValue":"0"},"location":{"stringValue":"Enschede"},"tickets":{"arrayValue":{}},"titel":{"stringValue":"SICK"}}}}},"createTime":"2020-02-26T13:56:36.291860Z","updateTime":"2020-02-26T13:56:36.291860Z"},"targetIds":[2]}}
[2020-06-20T03:23:48.291Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"targetChange":{"targetChangeType":"CURRENT","targetIds":[2],"resumeToken":"CgkIwI/KzbiP6gI=","readTime":"2020-06-20T03:23:48.175808Z"}}
[2020-06-20T03:23:48.297Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"targetChange":{"resumeToken":"CgkIwI/KzbiP6gI=","readTime":"2020-06-20T03:23:48.175808Z"}}
[2020-06-20T03:23:48.299Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get last remote snapshot version
[2020-06-20T03:23:48.304Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Apply remote event
[2020-06-20T03:23:48.319Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: notifyLocalViewChanges
[2020-06-20T03:23:48.330Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Release target
this._onEventsReceived(eventData): FINISHED
[2020-06-20T03:23:48.352Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"database":"projects/waarisdatfeestje-883cf/databases/(default)","removeTarget":2}
[2020-06-20T03:23:48.365Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Allocate target
[2020-06-20T03:23:48.370Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Execute query
[2020-06-20T03:23:48.377Z]  @firebase/firestore: Firestore (7.15.2): IndexFreeQueryEngine Using full collection scan to execute query: Query(target=Target(likes, filters: [user_email == [email protected]], orderBy: [__name__ (asc)]); limitType=F)
[2020-06-20T03:23:48.386Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"database":"projects/waarisdatfeestje-883cf/databases/(default)","addTarget":{"query":{"structuredQuery":{"from":[{"collectionId":"likes"}],"where":{"fieldFilter":{"field":{"fieldPath":"user_email"},"op":"EQUAL","value":{"stringValue":"[email protected]"}}},"orderBy":[{"field":{"fieldPath":"__name__"},"direction":"ASCENDING"}]},"parent":"projects/waarisdatfeestje-883cf/databases/(default)/documents"},"targetId":4}}
[2020-06-20T03:23:48.396Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"targetChange":{"targetChangeType":"REMOVE","targetIds":[2]}}
[2020-06-20T03:23:48.413Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"targetChange":{"targetChangeType":"ADD","targetIds":[4]}}
[2020-06-20T03:23:48.483Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"targetChange":{"targetChangeType":"CURRENT","targetIds":[4],"resumeToken":"CgkIrc3ZzbiP6gI=","readTime":"2020-06-20T03:23:48.429485Z"}}
[2020-06-20T03:23:48.489Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"targetChange":{"resumeToken":"CgkIrc3ZzbiP6gI=","readTime":"2020-06-20T03:23:48.429485Z"}}
[2020-06-20T03:23:48.491Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get last remote snapshot version
[2020-06-20T03:23:48.495Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Apply remote event
[2020-06-20T03:23:48.505Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: notifyLocalViewChanges
[2020-06-20T03:23:48.515Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Release target
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
START RENDER ITEM{EventsScreen}
this._onLikesReceived(likesData): FINISHED
[2020-06-20T03:23:48.651Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"database":"projects/waarisdatfeestje-883cf/databases/(default)","removeTarget":4}
[2020-06-20T03:23:48.731Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"targetChange":{"targetChangeType":"REMOVE","targetIds":[4]}}
[2020-06-20T03:24:48.658Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel transport closed
[2020-06-20T03:24:48.668Z]  @firebase/firestore: Firestore (7.15.2): PersistentStream stream callback skipped by getCloseGuardedDispatcher.

Here is the log of an action that tries to add data to firestore

[2020-06-20T03:26:41.615Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Locally write mutations
[2020-06-20T03:26:41.621Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: notifyLocalViewChanges
[2020-06-20T03:26:41.627Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get next mutation batch
[2020-06-20T03:26:41.630Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get next mutation batch
[2020-06-20T03:26:41.636Z]  @firebase/firestore: Firestore (7.15.2): Connection Creating WebChannel: https://firestore.googleapis.com/google.firestore.v1.Firestore/Write/channel [object Object]
[2020-06-20T03:26:41.645Z]  @firebase/firestore: Firestore (7.15.2): Connection Opening WebChannel transport.
[2020-06-20T03:26:41.647Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"database":"projects/waarisdatfeestje-883cf/databases/(default)"}
[2020-06-20T03:26:41.714Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel transport opened.
[2020-06-20T03:26:41.740Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"streamId":"0","streamToken":"GRBoQgKB9LW1"}
[2020-06-20T03:26:41.744Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"streamToken":"GRBoQgLhtLXlgIA=","writes":[{"update":{"name":"projects/waarisdatfeestje-883cf/databases/(default)/documents/eventCards/WXfUchsT6IlpSthpP8tA","fields":{"event":{"mapValue":{"fields":{"promo":{"stringValue":""},"titel":{"stringValue":"Titel"},"info":{"stringValue":""},"location":{"stringValue":"Location"},"date":{"timestampValue":"2020-06-12T14:42:42.000000000Z"},"tickets":{"arrayValue":{"values":[]}},"likes":{"integerValue":"0"}}}}}}}]}
[2020-06-20T03:26:41.774Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received error: {"code":400,"message":"invalid stream token","status":"INVALID_ARGUMENT"}
[2020-06-20T03:26:41.778Z]  @firebase/firestore: Firestore (7.15.2): PersistentStream close with error: FirebaseError: [code=invalid-argument]: invalid stream token
[2020-06-20T03:26:41.779Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Reject batch
[2020-06-20T03:26:41.789Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: notifyLocalViewChanges
[2020-06-20T03:26:41.798Z]  @firebase/firestore: Firestore (7.15.2): MemoryPersistence Starting transaction: Get next mutation batch

[Unhandled promise rejection: FirebaseError: invalid stream token]
* [native code]:null in construct
- node_modules/@babel/runtime/helpers/construct.js:30:26 in _construct
- node_modules/@babel/runtime/helpers/wrapNativeSuper.js:26:23 in Wrapper
* http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:157353:99 in A
* http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:176120:150 in <unknown>
- node_modules/@firebase/firestore/dist/index.rn.esm2017.js:15007:10 in yE
- node_modules/@firebase/webchannel-wrapper/dist/index.js:141:11 in <anonymous>
- node_modules/@firebase/webchannel-wrapper/dist/index.js:126:32 in Ca
- node_modules/@firebase/webchannel-wrapper/dist/index.js:1052:12 in Ec
- node_modules/@firebase/webchannel-wrapper/dist/index.js:435:50 in g.Ia
* http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:177474:20 in qc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:375:27 in ub
- node_modules/@firebase/webchannel-wrapper/dist/index.js:357:58 in g.dispatchEvent
- node_modules/@firebase/webchannel-wrapper/dist/index.js:141:11 in <anonymous>
- node_modules/@firebase/webchannel-wrapper/dist/index.js:126:32 in Ca
- node_modules/@firebase/webchannel-wrapper/dist/index.js:759:29 in Nc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:755:13 in Mc
- node_modules/@firebase/webchannel-wrapper/dist/index.js:751:26 in Mc
* [native code]:null in <unknown>
- node_modules/event-target-shim/dist/event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:566:23 in setReadyState
- node_modules/react-native/Libraries/Network/XMLHttpRequest.js:350:23 in __didReceiveIncrementalData
- node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12 in emit
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:436:47 in __callFunction
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:111:26 in __guard$argument_0
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:110:17 in __guard$argument_0
* [native code]:null in callFunctionReturnFlushedQueue

@schmidt-sebastian schmidt-sebastian self-assigned this Jun 20, 2020
@schmidt-sebastian
Copy link
Contributor

schmidt-sebastian commented Jun 20, 2020

Thanks for sending over the logs, which showcase the problem:

[2020-06-20T03:26:41.740Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel received: {"streamId":"0","streamToken":"GRBoQgKB9LW1"}
[2020-06-20T03:26:41.744Z]  @firebase/firestore: Firestore (7.15.2): Connection WebChannel sending: {"streamToken":"GRBoQgLhtLXlgIA="...

The streamToken in both lines needs to match. What happened in 7.15.3 is that we now use @firebase/util's base64 encoding on RN (unless another Polyfill is available). I just verified in a standalone test that our code does not roundtrip the provided stream token properly when running on Node.

In the meantime, you can "opt out" of this new code by installing an Base64 Polyfill like suggested here: https://stackoverflow.com/questions/60361519/cant-find-a-variable-atob

@djoiiwalraven
Copy link
Author

Did installing a Base64 Polyfill fix the issue for you in the standalone test? Because for me the stackoverflow suggestion isn't working

@schmidt-sebastian schmidt-sebastian changed the title [Unhandled promise rejection: FirebaseError: invalid stream token] When using firestore.collection(...).add({...}); in version 7.15.3 React Native build breaks Writes Jun 20, 2020
@schmidt-sebastian
Copy link
Contributor

schmidt-sebastian commented Jun 20, 2020

In the standalone test that just does a base64 encode/decode roundtrip, the encoding works if there is an atob/btoa fallback since this will be used instead. Despite that, I suggest using the Polyfill and v7.15.0.

@dzoba
Copy link

dzoba commented Jun 30, 2020

Do you know when this will be fixed? The Polyfill suggestion with 7.15.0 is not working for me.

Do you happen to know if there is a recent version I can use without this error?

@schmidt-sebastian can you describe how you'd do an "atob/btoa fallback"?

(This same problem is on stack overflow: https://stackoverflow.com/questions/62630423/firebase-react-native-invalid-stream-token)

@schmidt-sebastian
Copy link
Contributor

As of 7.15.4, we have reverted back to the previous behavior. You can find a guide to install the Polyfill here: https://stackoverflow.com/questions/60361519/cant-find-a-variable-atob/60369040#60369040

In the next release (fingers crossed), the Polyfill will no longer be needed.

@djoiiwalraven
Copy link
Author

I just wanna say, with the new update 7.15.5 this issue was resolved. thank you! 👍

@schmidt-sebastian
Copy link
Contributor

I am still kind of embarrassed by how long this took, but thanks for letting me know that I can now move on to other things :)

@firebase firebase locked and limited conversation to collaborators Jul 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants