ostyjs / nostr-hooks

React hooks for developing Nostr clients. It's simple yet intelligent.
https://www.npmjs.com/package/nostr-hooks
MIT License
53 stars 12 forks source link

useSubscribe getting stuck #26

Open Czino opened 1 month ago

Czino commented 1 month ago

I found that if you switch fast enough between filters, the useSubscribe hook gets stuck on waiting for events. In other words eose is never true.

I was able to reproduce it by quickly updating the url in the input field (e.g. move cursor to last position, quickly press delete and 3) It will then stay stuck on Fetching messages...

https://codesandbox.io/p/sandbox/cldj6h?file=%2Fsrc%2FApp.js

Interestingly, if you set { closeOnEose: true }, it behaves as expected. However, in my use case of developing a chat, I would like to not close the subscription.

Czino commented 1 month ago

In some cases, you don't even need to update the filters quickly. I suspect it depends whether eose is reached or not

sepehr-safari commented 1 month ago

Thanks for this bug report. I guess a temporary fix would be using a cache like NDK-Cache-Dexie. (can you confirm?) But I will find a way to fix it permanently.

Czino commented 1 month ago

I tried to use @nostr-dev-kit/ndk-cache-dexie as cache adapter, but the problem persists unfortunately