nostr-dev-kit / ndk

Nostr Development Kit with outbox-model support
https://nostr-dev-kit.github.io/ndk/
MIT License
366 stars 99 forks source link

fetchProfile() doesn't work on +page.server.ts ?? #220

Open manimejia opened 6 months ago

manimejia commented 6 months ago

I'm really not sure what's going on... but svelte page loading is non responsive with no errors. I've isolated the problem to ndkuser.fetchProfile() being called and everything just stops.

All I'm trying to do is load on server side an ndkuser and profile from Nip05 in URL. My same code block pasted into onMount() on the +page.svelte works. (Not loaded server side) But when pasted into PageLoad() in +page.ts (or PageServerLoad in +page.server.ts) it fails at fetchProfile().

erskingardner commented 6 months ago

I've also run into this from time to time too. I've not had a chance to dig into it yet but wanted to at least say that I believe this is reproducible.

pablof7z commented 6 months ago

are you sure you are connected on the server side? keep in mind those are two separate connections; worth checking what's on ndk.pool.connectedRelays (iirc) on the server side, you might be missing an ndk.connect() on the server.

Sebastix commented 6 months ago

I'm having this issue also quite a lot (I'm not using svelte components, but just the NDK package). With Alby as a signer the code just stops and does not throw any errors on the console (application and extension). With the extension nos2x is succeeds around 90% of the time, but the same 'bug' pops up from time to time.

The issue I also mentioned on Nostr earlier where I tagged @pablof7z https://nostrudel.ninja/#/n/nevent1qvzqqqqqqypzqpnrnguxe8qszsshvgkvhn6qjzxy7xsvx03rlrtddr62haj4lrm3qy88wumn8ghj7mn0wvhxcmmv9uq36amnwvaz7tmwdaehgu3wd46hg6tw09mkzmrvv46zucm0d5hsqg9s32gxctx2u5u4cp3yzqdnsx72lyy7j6vwcyngrfj6n2em7ns28vqpcrs8

erskingardner commented 6 months ago

hmm, that makes me wonder if the block is the signer asynchronously waiting for the user to approve. We might not notice it often because we've told our signers to just remember our choice and not ask again...

manimejia commented 6 months ago

@Sebastix I think your issue is different (related?) from mine. What I'm reporting is specifically when calling fetchProfile() from server side code.

@pablof7z :

are you sure you are connected on the server side? keep in mind those are two separate connections; worth checking what's on ndk.pool.connectedRelays (iirc) on the server side, you might be missing an ndk.connect() on the server.

Yes. Does look like NDK is connected on server side. But still the code hangs up. I've resorted (for now) to pull kind0 profile events from api.nostr.wine using fetch() on server side. This works.

Sebastix commented 6 months ago

@manimejia It's the same codebase we're using for what I can see which works on both sides (server and client).

manimejia commented 1 month ago

This bug nailed me again ... after months of "other stuff" development, I come back to NDK and forgot that it does not connect from the server.

What is the issue here... and how might I work around it?

pablof7z commented 1 month ago

This bug nailed me again ... after months of "other stuff" development, I come back to NDK and forgot that it does not connect from the server.

What is the issue here... and how might I work around it?

do you have the websockets polyfill?

manimejia commented 1 month ago

Thanks Pablo. That did work. I found the README from nostr-tools to be helpful:


To use this on Node.js you first must install ws and call something like this:

import { useWebSocketImplementation } from 'nostr-tools/pool'
// or import { useWebSocketImplementation } from 'nostr-tools/relay' if you're using the Relay directly

import WebSocket from 'ws'
useWebSocketImplementation(WebSocket)