Skip to content
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

Question: useRXCollection not able to notice deletion and recreation of collection in one sitting #58

Open
de-robat opened this issue Dec 16, 2022 · 1 comment

Comments

@de-robat
Copy link

Hello, i am currenlty facing an issue where users of my app are logging in and out right after eachother. while logging out im removing some user specific collections, which leads to the replicationstate of collections beeing reset in the rxdb itself. so far so good.

but now it happen that users login right after again, and the old references to useRXCollections are now destroyed:true, as one can expect.

Im recreating the collections properly before the user can login again, but this is not picked up by rxdb-hooks anymore as if the collection has been found immidiatley there is no subscription to the "newCollection$" subject:

useEffect(() => {
		if (!db) {
			return;
		}
		const found = db[name];
		if (found) {
			setCollection(found); <------ here we wont subscribe
		} else {
			const sub = db.newCollections$.subscribe(col => {
				if (col[name]) {
					// We don't unsubscribe so that we get notified
					// and update collection if it gets deleted/recreated
					setCollection(col[name]);
				}
			});
			return () => {
				sub.unsubscribe();
			};
		}
	}, [db, name]);

i am now wondering why this is the behaviour rxdb-hooks opt for, and if i get side effects im not aware of if i subscribe to the subject anyhow. Or ist this just a usecase that has not been tought of and therfore is not covered?

@russelldavis
Copy link

Looks like this was fixed here: 36c6bcf#diff-8056012e2d5a20d01339760c71c5d9363406b3de875d94246041ae2b0e52fbaa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants