Skip to content

Conversation

0xAlunara
Copy link
Collaborator

@0xAlunara 0xAlunara commented Sep 12, 2025

By the light this shit is nasty.

So the problem is, when you visit the website for the first time the CurveJS library gets hydrated without an RPC. But to fetch user walles balances, you need a CurveJS instance with an RPC. After a short time, a second hydration occurs with an RPC. However, there's a brief moment in time where you have a CurveJS instance with RPC, but it's not yet hydrated. Only the old NoRPC version is hydrated. There's no easy way to detect if the new RPC'd version of CurveJS is hydrated, so out of caution if you want to call fetchUserPoolInfo you have to make absolutely sure the pool we're fetching data from is hydrated, hence the preceding calls of fetchUserPoolList.

Ugh, this one ugly fix. Can't wait until we get rid of this whole library and can rely on just TanStack queries, which would be a proper fix.

EDIT: it's still not 100% fixed but it's better. Burn this shit with fire ugh

If you go to a pool page in prod and refresh with F5 you can reproduce it
image

Copy link

vercel bot commented Sep 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
curve-dapp Ready Ready Preview Comment Sep 12, 2025 0:37am
curve-dapp-storybook Ready Ready Preview Comment Sep 12, 2025 0:37am

void fetchUserPoolInfo(curve, poolId, true)
if (
curve &&
!curve.isNoRPC &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not make any sense. Why would curve have a signer address (haveAddress = !!curve.signerAddress) and no RPC?

Suggested change
!curve.isNoRPC &&

If that is really happening we must fix it, not work around it

Copy link
Collaborator Author

@0xAlunara 0xAlunara Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's the chain of events in chronological order that hopefully makes the problem more clear:

  1. Open app
  2. CurveJS inits with no RPC
  3. CurveJS gets hydrated
  4. CurveJS gets init again but this time with RPC
  5. The useEffect that calls fetchUserPoolInfo and relies on curvejs gets called. The function fetchUserPoolInfo however relies on a hydrated version of curvejs (as it requires pools being fetched etc). This fails, as the new curvejs with RPC is not yet hydrated
  6. CurveJS with RPC gets hydrated

So the fix was aimed at hydrating the specific part for fetchUserPoolInfo when we get a new curvejs with RPC. The issue basically boils down to having a curvejs that has an RPC but is not yet hydrated. You can't wait in the useEffect for curvejs to be hydrated because there's no such tracking. We only have an isHydrated check at at the root in the tanstack router, but there's no 'hasRehydratedWithRpcThisTime'.

That sounds like a band-aid too. This ticket was outside of the sprint so I'll leave it be for now.
Fwiw a real solution would be Tanstackifying everything and getting rid of the hydration, but that's a step too big for now.

Copy link
Collaborator

@DanielSchiavini DanielSchiavini Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's necessary we can add a hydration flag in the connection context. Or even inject a property in the curve object.
We should also fix the double-hydration issue, I already tried to fix this:

if (isReconnecting) return // wait for wagmi to auto-reconnect

Copy link
Collaborator

@DanielSchiavini DanielSchiavini Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also #1022 and

// `useAccount` and `useClient` are not always in sync, so check both. `isReconnecting` is set when switching pages
isReconnecting: !address && (isReconnecting || isConnected),

@0xAlunara 0xAlunara marked this pull request as draft September 16, 2025 14:30
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.

2 participants