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

useLiveQuery does not update when multiple items are deleted #2067

Closed
wesbos opened this issue Sep 6, 2024 · 3 comments
Closed

useLiveQuery does not update when multiple items are deleted #2067

wesbos opened this issue Sep 6, 2024 · 3 comments

Comments

@wesbos
Copy link

wesbos commented Sep 6, 2024

hello! I have a query like this:

const images = useLiveQuery(() => db.images.reverse().toArray());

When I delete a single item, it is reactive and updates:

<button onClick={() => db.images.where('id').equals(2).delete()}>Delete</button>

But when I try to delete multiple items at once, it deletes the item, but the query does not react:

<button onClick={() => db.images.where('id').above(0).delete()}>Delete</button>

I thought it may be related to: #2021 but it seem anything that deletes more than one record doesnt cause reactivity

@imarinoff
Copy link

it seems that dexie observable in general does not react well to bulk actions.
On bulkAdd and bulkPut I get:
{
"name": "DatabaseClosedError",
"message": "Database has been closed",
"inner": null
}
and on changes event does not get triggered

console.js:288 DexieError2 {name: 'DatabaseClosedError', message: 'Database has been closed', inner: null}
overrideMethod @ console.js:288
(anonymous) @ table.ts:73
(anonymous) @ promise.js:721
(anonymous) @ promise.js:426
callListener @ promise.js:426
endMicroTickScope @ promise.js:475
Table2._trans @ table.ts:79
Collection2._read @ collection.ts:50
Collection2.toArray @ collection.ts:166
readChanges @ Dexie.Observable.js:317
(anonymous) @ Dexie.Observable.js:290
(anonymous) @ vip.ts:15
usePSD @ promise.js:709
newScope @ promise.js:590
vip @ vip.ts:13
onLatestRevisionIncremented @ Dexie.Observable.js:289
(anonymous) @ chaining-functions.js:74
(anonymous) @ chaining-functions.js:74
(anonymous) @ wakeup-observers.js:11
ignoreTransaction @ dexie-static-props.ts:111
wakeupObservers @ wakeup-observers.js:10
(anonymous) @ override-create-transaction.js:29
Dexie: read _changes
Table2._trans @ table.ts:43
Collection2._read @ collection.ts:50
Collection2.toArray @ collection.ts:166
readChanges @ Dexie.Observable.js:317
(anonymous) @ Dexie.Observable.js:290
(anonymous) @ vip.ts:15
usePSD @ promise.js:709
newScope @ promise.js:590
vip @ vip.ts:13
onLatestRevisionIncremented @ Dexie.Observable.js:289
(anonymous) @ chaining-functions.js:74
(anonymous) @ chaining-functions.js:74
(anonymous) @ wakeup-observers.js:11
ignoreTransaction @ dexie-static-props.ts:111
wakeupObservers @ wakeup-observers.js:10
(anonymous) @ override-create-transaction.js:29
setTimeout
(anonymous) @ override-create-transaction.js:27
(anonymous) @ transaction-constructor.ts:59
(anonymous) @ promise.js:721
callListener @ promise.js:426
endMicroTickScope @ promise.js:475
(anonymous) @ promise.js:544

@dfahlander
Copy link
Collaborator

hello! I have a query like this:

const images = useLiveQuery(() => db.images.reverse().toArray());

When I delete a single item, it is reactive and updates:

<button onClick={() => db.images.where('id').equals(2).delete()}>Delete</button>

But when I try to delete multiple items at once, it deletes the item, but the query does not react:

<button onClick={() => db.images.where('id').above(0).delete()}>Delete</button>

I thought it may be related to: #2021 but it seem anything that deletes more than one record doesnt cause reactivity

Thanks @wesbos, I will look into this.

@dfahlander
Copy link
Collaborator

@imarinoff The DatabaseClosedError happens when the database has been closed and seem to be off-topic for this issue. Please file another issue with a repro for when it happens

dfahlander pushed a commit that referenced this issue Oct 14, 2024
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

3 participants