rxdb: Subscriber breaks with react-native and async storage

Case

I was just developing an app using rxdb and react-native, when the time came to update a record on the database, suddenly a subscription on a collection broke

Issue

triggering an update on document (via atomicSet or any other update operation) breaks the query response on other parts of the app

Reproducible example:

I’ve created a repo with the issue:

https://github.com/ospfranco/rxdb-rn-bug

to reproduce:

  1. clone and run the app: yarn, yarn ios
  2. click on add random node a couple of times, so you have some elements
  3. click on one of the ids on the list
  4. click on randomly update selected node, it will do an atomic update and all of the sudden the list of elements will be cleared, and only the selected node will remain

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 24 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Just FYI, I got the sqlite2 adapter working by simply modifying the podspec, the bug is not present there, I would suggest removing the old adapter documentation since it is abandoned anyways, I submitted a PR that includes macOS support:

https://github.com/craftzdog/react-native-sqlite-2/pull/82

@pubkey I have updated the original repo to expo, hopefully that will save you some time.

I copied&pasted the code for debug, nothing out of the ordinary is logged:

WARNING
15:43
node changed, Object {
  "_rev": "2-62755508d77e48db904665a18f72bc32",
  "authorId": "HARDCODED AUTHOR",
  "createdAt": 1592746710509,
  "id": "bcfa09db-315a-4a58-93ac-861c2ea729cc",
  "text": "0.624582943994004",
  "type": "text",
  "updatedAt": 1592746710513,
}

Stack trace:
  node_modules/react-native/Libraries/YellowBox/YellowBox.js:71:8 in console.warn
  node_modules/expo/build/environment/muteWarnings.fx.js:18:23 in warn
  App.js:56:27 in node.$.subscribe$argument_0
  node_modules/rxjs/internal/Subscriber.js:204:12 in SafeSubscriber.prototype.__tryOrUnsub
  node_modules/rxjs/internal/Subscriber.js:142:17 in SafeSubscriber.prototype.next
  node_modules/rxjs/internal/Subscriber.js:88:25 in <anonymous>
  node_modules/rxjs/internal/Subscriber.js:65:18 in prototype.next
  node_modules/rxjs/internal/BehaviorSubject.js:34:24 in prototype._subscribe
  node_modules/rxjs/internal/Observable.js:43:12 in prototype._trySubscribe
  node_modules/rxjs/internal/Observable.js:27:13 in prototype.subscribe
  node_modules/rxjs/internal/Observable.js:27:13 in prototype.subscribe
  App.js:54:26 in <anonymous>
  node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
  node_modules/promise/setimmediate/core.js:123:25 in setImmediate$argument_0
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14 in _callTimer
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17 in _callImmediatesPass
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30 in callImmediates
  [native code]:null in callImmediates
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:6 in __callImmediates
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:6 in __guard$argument_0
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:142:17 in __guard$argument_0
  [native code]:null in flushedQueue
  [native code]:null in callFunctionReturnFlushedQueue
  ...
WARNING
15:43
node changed, Object {
  "_rev": "3-7ba98b066a4044a68da831f88b0b9d95",
  "authorId": "HARDCODED AUTHOR",
  "createdAt": 1592746710509,
  "id": "bcfa09db-315a-4a58-93ac-861c2ea729cc",
  "text": "0.6055807884750679",
  "type": "text",
  "updatedAt": 1592746710513,
}

Stack trace:
  node_modules/react-native/Libraries/YellowBox/YellowBox.js:71:8 in console.warn
  node_modules/expo/build/environment/muteWarnings.fx.js:18:23 in warn
  App.js:56:27 in node.$.subscribe$argument_0
  node_modules/rxjs/internal/Subscriber.js:204:12 in SafeSubscriber.prototype.__tryOrUnsub
  node_modules/rxjs/internal/Subscriber.js:142:17 in SafeSubscriber.prototype.next
  node_modules/rxjs/internal/Subscriber.js:88:25 in <anonymous>
  node_modules/rxjs/internal/Subscriber.js:65:18 in prototype.next
  node_modules/rxjs/internal/Subject.js:59:12 in prototype.next
  node_modules/rxjs/internal/BehaviorSubject.js:50:30 in <anonymous>
  http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:130874:31 in _handleChangeEvent
  [native code]:null in _handleChangeEvent
  http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:153496:40 in <unknown>
  node_modules/rxjs/internal/Subscriber.js:204:12 in SafeSubscriber.prototype.__tryOrUnsub
  node_modules/rxjs/internal/Subscriber.js:142:17 in SafeSubscriber.prototype.next
  node_modules/rxjs/internal/Subscriber.js:88:25 in <anonymous>
  node_modules/rxjs/internal/Subscriber.js:65:18 in prototype.next
  node_modules/rxjs/internal/operators/filter.js:51:20 in FilterSubscriber.prototype._next
  node_modules/rxjs/internal/Subscriber.js:65:18 in prototype.next
  node_modules/rxjs/internal/operators/filter.js:51:20 in FilterSubscriber.prototype._next
  node_modules/rxjs/internal/Subscriber.js:65:18 in prototype.next
  node_modules/rxjs/internal/operators/filter.js:51:20 in FilterSubscriber.prototype._next
  node_modules/rxjs/internal/Subscriber.js:65:18 in prototype.next
  node_modules/rxjs/internal/Subject.js:59:12 in prototype.next
  node_modules/rxdb/dist/lib/rx-database.js:127:22 in $emit
  [native code]:null in $emit
  http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:131078:21 in <unknown>
  node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
  node_modules/promise/setimmediate/core.js:123:25 in setImmediate$argument_0
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:146:14 in _callTimer
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:194:17 in _callImmediatesPass
  node_modules/react-native/Libraries/Core/Timers/JSTimers.js:458:30 in callImmediates
  [native code]:null in callImmediates
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:407:6 in __callImmediates
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:143:6 in __guard$argument_0
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:384:10 in __guard
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:142:17 in __guard$argument_0
  [native code]:null in flushedQueue
  [native code]:null in invokeCallbackAndReturnFlushedQueue
  ...

But you can try it yourself more easily now I hope