Skip to content

fix: use the app's QueryClient in useConnect/useAddToNetwork - #3053

Open
gomesalexandre wants to merge 1 commit into
DefiLlama:mainfrom
gomesalexandre:fix_useconnect_queryclient
Open

fix: use the app's QueryClient in useConnect/useAddToNetwork#3053
gomesalexandre wants to merge 1 commit into
DefiLlama:mainfrom
gomesalexandre:fix_useconnect_queryclient

Conversation

@gomesalexandre

Copy link
Copy Markdown

closes #3052

bug

useConnect and useAddToNetwork each build a new QueryClient and invalidate it:

const queryClient = new QueryClient();
// ...
onSettled: () => { queryClient.invalidateQueries(); }

That client is disconnected from the one in pages/_app.js (<QueryClientProvider client={queryClient}>), so invalidateQueries() invalidates an empty, unused cache. After connecting a wallet or adding a network, the app's queries never refetch.

fix

Use useQueryClient() to get the client from context, so the invalidation targets the app's real cache. Two-line change in each hook (react-query v4, useQueryClient is the v4 hook).

receipts

next build  →  ✓ Compiled successfully

Both hooks call useQueryClient() unconditionally at the top of the hook (rules-of-hooks safe), and the QueryClientProvider in pages/_app.js supplies the client.

Both hooks constructed a new QueryClient() and called invalidateQueries() on
it, which targets a fresh disconnected cache and does nothing to the app's
actual queries provided in _app.js. Use useQueryClient() so the invalidation
hits the real cache and dependent queries refetch after connecting a wallet or
adding a network.

Co-Authored-By: Claude Opus 4.8 <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.

useConnect/useAddToNetwork invalidate a disconnected QueryClient (no-op)

1 participant