Skip to content

fix: stabilize user-profile save and hydration flow#319

Open
Rustix69 wants to merge 4 commits intoshopstr-eng:mainfrom
Rustix69:fix/user-profile-save-websocket-hydration
Open

fix: stabilize user-profile save and hydration flow#319
Rustix69 wants to merge 4 commits intoshopstr-eng:mainfrom
Rustix69:fix/user-profile-save-websocket-hydration

Conversation

@Rustix69
Copy link
Copy Markdown

@Rustix69 Rustix69 commented Apr 3, 2026

Summary

  • Fixes websocket publish race in NostrManager by awaiting relay reconnects before publish/subscribe.
  • Fixes blank/late rendering on /settings/user-profile by tying loading UI to ProfileMapContext hydration state instead of a premature local loading flag.
  • Starts an early fetch for the signed-in user profile in app bootstrap (pages/_app.tsx) so profile data is available sooner.

Problem

Editing and saving profile details on /settings/user-profile could trigger:

  • WebSocket is already in CLOSING or CLOSED state errors during publish.
  • Temporary blank profile form fields until later fetch/cache hydration.

Root cause

  • Relay reconnect was initiated but not awaited before publish/subscribe.
  • User-profile page cleared local loading too early, before global profile context was hydrated.
  • Current-user profile fetch happened late in initialization sequence.

Changes

  • utils/nostr/nostr-manager.ts
    • Made keepAlive async.
    • Await reconnect completion in both subscribe and publish.
  • pages/settings/user-profile.tsx
    • Removed premature local fetching state behavior.
    • Derived loading state from profile context readiness + current user profile presence.
    • Hydrates form only after profile context is no longer loading.
  • pages/_app.tsx
    • Added early current-user profile fetch during startup and awaited it before broader profile fetch completion.

Test plan

  • Unit tests: npm test -- --runInBand utils/nostr/__tests__/nostr-manager.test.ts
  • Manually open /settings/user-profile and verify fields do not render blank before hydration.
  • Edit profile fields and click Save Profile; confirm no CLOSED/CLOSING websocket errors.
  • Reload/revisit /settings/user-profile and verify saved values appear promptly.

Await relay reconnection before nostr publish/subscribe to prevent CLOSED/CLOSING websocket errors during profile saves. Improve user-profile loading by relying on profile context hydration and prefetching the signed-in user profile earlier in app initialization to avoid blank form states.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

@Rustix69 is attempting to deploy a commit to the shopstr-eng Team on Vercel.

A member of the Team first needs to authorize it.

@Rustix69
Copy link
Copy Markdown
Author

Rustix69 commented Apr 3, 2026

Screencast.from.2026-04-04.04-38-10.webm

Await relay reconnects before publish/subscribe and guard fetch EOSE handling so sub.close is never called before subscription initialization. Improve user-profile hydration by using context-driven loading and early current-user profile prefetch to avoid blank fields and delayed updates.
@arnavkirti
Copy link
Copy Markdown
Contributor

arnavkirti commented Apr 6, 2026

Thank you! Already covered in #294

Also, please refrain from changing the docker-compose.yml file.

@GautamBytes
Copy link
Copy Markdown
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] User Profile save throws WebSocket CLOSED errors and profile fields load blank initially

3 participants