Skip to content

fix(profile): preserve label account type across page refreshes - #14548

Merged
dylanjeffers merged 1 commit into
mainfrom
fix/label-account-type-revert
Aug 5, 2026
Merged

fix(profile): preserve label account type across page refreshes#14548
dylanjeffers merged 1 commit into
mainfrom
fix/label-account-type-revert

Conversation

@dylanjeffers

Copy link
Copy Markdown
Contributor

Problem

Switching from artist to label account appeared to work, but reverted to artist within ~10 seconds of a page refresh. Reproduced on @FutureVibes and @theboathouse.

Root Cause

Three bugs conspired to cause the revert:

Bug 1 — useUpdateProfile: no onSuccess handler

mutationFn calls sdk.users.updateUser() (entity manager, waits for block confirmation), then fetches fresh user data via sdk.users.getUser() and returns it. But there was no onSuccess handler, so the server-confirmed data was silently discarded. The optimistic update from onMutate stayed in the React Query cache, but nothing re-confirmed it after the write landed on-chain.

Bug 2 — useUpdateProfile: broken onError rollback

onError rolled back with { ...context.previousMetadata, ...metadata } instead of context.previousMetadata alone — applying the failed mutation on top of the pre-mutation state, the opposite of a rollback.

Bug 3 — setLocalStorageAccountAndUser: overwrites recent mutations

fetchAccountAsync runs on every page load and calls setLocalStorageAccountAndUser, which writes the server-fetched accountUser directly to localStorage. This overwrites any recent optimistic updates (e.g. profile_type: label) that haven't yet propagated to all discovery nodes. On the next reload, fetchLocalAccountAsync reads this stale localStorage value and primes the cache with profile_type: null, reverting the user back to artist.

Fix

packages/common/src/api/tan-query/users/useUpdateProfile.ts

  • Added onSuccess that re-applies the mutation variables to the query cache (forceReplace: true). Uses the mutation variables rather than the raw server response to guard against discovery-node propagation lag — the getUser call may hit a node that has not yet indexed the confirmed block.
  • Fixed onError to roll back with context.previousMetadata only (not spread with current metadata).

packages/common/src/store/account/sagas.ts

  • setLocalStorageAccountAndUser now prefers the React Query cached user over the server-fetched response when writing to localStorage. The cache already holds the correct post-mutation state; the server may lag due to node propagation. Falls back to the server value if the cache is empty (first load, no prior mutations).

Testing

Manually verify with a label-eligible account:

  1. Go to Settings → Account Type → toggle to Label
  2. Refresh the page — should still show Label immediately and after ~10 s
  3. Refresh again — should remain Label

Two bugs caused profile_type to revert to null after switching to label:

1. useUpdateProfile had no onSuccess handler, so the server-confirmed
   data returned by mutationFn was discarded entirely. The optimistic
   update was left in cache but nothing re-confirmed it after the write
   landed.

   Fix: add onSuccess that re-applies the mutation variables (not the
   raw server response) to the query cache with forceReplace: true.
   Using variables rather than the server response guards against
   discovery-node propagation lag — the getUser call may hit a node
   that has not yet indexed the confirmed block.

2. onError rolled back with { ...context.previousMetadata, ...metadata }
   instead of context.previousMetadata alone, effectively applying the
   failed mutation on top of the pre-mutation state instead of
   restoring it.

   Fix: roll back with context.previousMetadata only.

3. setLocalStorageAccountAndUser (called inside fetchAccountAsync on
   every page load) wrote the server-fetched accountUser directly to
   localStorage, overwriting any recent optimistic updates such as
   profile_type. On the next reload, fetchLocalAccountAsync would read
   this stale localStorage value and prime the cache with profile_type:
   null, reverting the user to artist.

   Fix: prefer the React Query cache over the server response when
   writing to localStorage. The cache already holds the correct
   post-mutation state; the server response may lag due to node
   propagation. If the cache is empty (first load), fall back to the
   server value as before.
@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6db0051

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@dylanjeffers
dylanjeffers merged commit 5f34874 into main Aug 5, 2026
17 checks passed
@dylanjeffers
dylanjeffers deleted the fix/label-account-type-revert branch August 5, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant