Skip to content

fix: optimistic join data survives subgraph null response#220

Open
hudsonhrh wants to merge 1 commit intomainfrom
hudsonhrh/fix-optimistic-guard
Open

fix: optimistic join data survives subgraph null response#220
hudsonhrh wants to merge 1 commit intomainfrom
hudsonhrh/fix-optimistic-guard

Conversation

@hudsonhrh
Copy link
Copy Markdown
Member

Summary

After vouch-first join, the profileHub showed WelcomeClaimPage ("claim your role") instead of the user's profile, even though optimisticJoin correctly set userData.hatIds.

Root cause

The FETCH_USER_DATA_NEW query fires when profileHub mounts. The subgraph hasn't indexed the new member yet, so it returns user: null. The query's useEffect (line 166) then runs setUserData({}), wiping out the optimistic hatIds. ProfileHub checks userData?.hatIds?.length > 0 — now it's 0, so WelcomeClaimPage renders.

Fix

Added optimisticGuardRef (a React ref, not state):

  • Set to true in optimisticJoin() — blocks the null-user branch from clearing state
  • Cleared after 8 seconds when the real subgraph refetch fires — normal data flow resumes
  • Uses a ref to avoid re-renders or useEffect dependency issues

Test plan

  • Vouch-first join → redirects to profileHub with full profile (not WelcomeClaimPage)
  • After 8 seconds, subgraph data replaces optimistic data seamlessly
  • Normal page load (no optimistic data) still shows WelcomeClaimPage for non-members

🤖 Generated with Claude Code

After optimisticJoin, the subgraph hasn't indexed the new member yet,
so FETCH_USER_DATA_NEW returns user: null. The query useEffect was
clearing all state (userData, hasMemberRole, hasExecRole) which wiped
out the optimistic data and showed WelcomeClaimPage instead of profileHub.

Added optimisticGuardRef that prevents the null-user branch from
clearing state while optimistic data is active. The guard is cleared
after 8 seconds when the real subgraph refetch replaces it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant