Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest wagmi and @tanstack/react-query are not compatible with StructuralSharing (breaks dev) #4233

Closed
1 task done
akshatmittal opened this issue Aug 31, 2024 · 7 comments

Comments

@akshatmittal
Copy link

akshatmittal commented Aug 31, 2024

Check existing issues

Describe the bug

Wagmi enables StructuralSharing by default, however creating a new project right with latest wagmi and tanstack query does not work, breaks all queries in dev that include any BigInt. Every query that includes a BigInt (including native ones) returns an error.

The only way to fix it is by disabling structuralSharing explicitly and globally.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/new-wagmi-d1zd7f?file=src%2Fmain.tsx,src%2FBalanceAtom.tsx

Steps To Reproduce

Just look at console logs. And look at the balanceData output for the error from query.

The error looks like:

StructuralSharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [["balance",{"address":"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266","chainId":1}]]: TypeError: Do not know how to serialize a BigInt

This is even after enabling custom hashFn included in wagmi/query.

What Wagmi package(s) are you using?

wagmi

Wagmi Package(s) Version(s)

2.12.8

Viem Version

2.21.1

TypeScript Version

5.5.4

Anything else?

No response

@maggo
Copy link

maggo commented Sep 2, 2024

Can confirm this is happening out of the box and with custom hashFn on the query client.

@W3stside
Copy link

W3stside commented Sep 3, 2024

+1 for this issue. looks like a BigInt non serialisable issue in the structuralSharing default logic. for my project the balance check was failing as args: [0n] is returned and react-query cant serialise the BigInt balance return

gershon added a commit to ArkProjectNFTs/ark-market that referenced this issue Sep 3, 2024
- rewrite balance hook to avoid structuralSharing error
(wevm/wagmi#4233)
- use starknet price instead of ethereum for starknet balance in usd
@phamhongphuc
Copy link

Workaround: Modify default QueryClient

https://wagmi.sh/react/getting-started#setup-tanstack-query

import { QueryClient } from '@tanstack/react-query';
import { structuralSharing } from '@wagmi/core/query';

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      structuralSharing,
    },
  },
});

thecil added a commit to thecil/thecil-escrow-dapp that referenced this issue Sep 6, 2024
@jxom
Copy link
Member

jxom commented Sep 8, 2024

I opened a PR to fix this upstream in React Query: TanStack/query#8030

@jxom
Copy link
Member

jxom commented Sep 9, 2024

Fixed https://github.com/TanStack/query/releases/tag/v5.55.3 – please update to @tanstack/[email protected]

@jxom jxom closed this as completed Sep 9, 2024
MartianGreed pushed a commit to BibliothecaDAO/market that referenced this issue Sep 10, 2024
- rewrite balance hook to avoid structuralSharing error
(wevm/wagmi#4233)
- use starknet price instead of ethereum for starknet balance in usd
@pclaesen
Copy link

@tanstack/[email protected]

Thank you so much :-D!

Copy link
Contributor

This issue has been locked since it has been closed for more than 14 days.

If you found a concrete bug or regression related to it, please open a new bug report with a reproduction against the latest Wagmi version. If you have any questions or comments you can create a new discussion thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants