-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Subscriber breaks with react-native and async storage #2286
Comments
Can you disable eventReduce and try if that still occurs? |
node.$.subscribe((changeEvent) =>
console.warn(`node changed`, changeEvent),
); the change gets logged, saving was never a problem |
Have you done a console log here? maybe the change detection is just broken but the data actually gets emitted. |
I did, but the problem is not the saving of the data... have you seen the code? there are two calls:
whenever I write something (1) breaks, and returns the "cached" result of the |
oh sorry, you linked directly to the code, yes, I added a console log, but really... only one item is returned, I did see a funny behavior sometimes though, all the items would be returned a couple of times, but then there would be two more emitted values with only 1 entry |
Hi. Few more stuff to try:
I have no iOS devices. If this is reproducible on android I will start digging deeper with your repo. |
error: Error: Unable to resolve module It seems like it uses some Node.js api, so it is not compatible with react-native
|
I do not get it started
Can I somehow start this without having to install the full android emulator? |
it's not an expo app, it is pure react native, so I guess not, either download android studio or you can just copy&paste the code in a new expo project, after all it's only like 3 files and the dependencies |
Ok I will try when I find the time. Can you try enabling pouchdb-debug? Then we could see if this is a RxDB bug or a pouch bug. import pouchdbDebug from 'pouchdb-debug';
import {
PouchDB
} from 'rxdb';
PouchDB.plugin(pouchdbDebug);
// PouchDB.debug.enable('*'); Also I have seen you are using a null-check here are you sure the db variable is never null at that point? |
@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:
But you can try it yourself more easily now I hope |
Thank you, I started it and I can reproduce the problem now. |
It works correctly when I remove the sorting db.nodes
.find()
// .sort({createdAt: 'desc'})
.$.subscribe((dbNodes) => {
console.warn('query$ emitted new result with ' + dbNodes.length + ' docs');
if (dbNodes) {
setNodes(dbNodes);
}
}); |
I added some logging to the rxdb/dist/lib in the node_modules. |
Ok so directly checking a plain pouchdb query after the update will also return the wrong results async function randomlyUpdate() {
if (selectedNode) {
await selectedNode.atomicSet('text', `${Math.random()}`);
}
const plainPouchResults = await db.nodes.pouch.find({
selector: {
createdAt: {
$gt: 0
}
},
sort: ['createdAt']
});
console.warn('plainPouchResults: ' + JSON.stringify(plainPouchResults));
} |
yeah, I believe it is an adapter bug, somehow the wrong answer is being cached |
hi @pubkey, is there any way I can support you with this? |
I think this is a pouchdb/asyncstorage bug. |
well, yeah, it is a asyncstorage bug, but... it is a major issue, react-native just does not work, rxdb cannot be used on production if the data cannot be updated, don't want to put to much pressure on this, but if there will be no plans to fix it, you might as well just remove it from the list of supported platforms |
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: |
I added a warning to the docs. Thank you for your investigation. |
Hi @ospfranco, when you got this working with the sqlite2 adapter, were you using expo or bare react-native? Expo has its own version of sqlite and I am trying to integrate it without success. |
Just wanted to add that I am also unable to use the sqlite adapter with expo. Would be nice if there was an example in the docs demonstrating the use of expo-sqlite instead of react-native-sqlite-2. |
@infosisio make a PR |
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:
yarn
,yarn ios
add random node
a couple of times, so you have some elementsrandomly 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 remainThe text was updated successfully, but these errors were encountered: