fix(react): forward includeTransactions and blockTag to useBlock watcher - #5226
fix(react): forward includeTransactions and blockTag to useBlock watcher#5226Kropiunig wants to merge 1 commit into
Conversation
`useBlock` passes only `config` and `chainId` into `useWatchBlocks`, so the
watcher fetches blocks with viem's defaults (`includeTransactions: false`,
`blockTag: 'latest'`) and writes them into a query key that was built with
the caller's `includeTransactions`/`blockTag`.
With `useBlock({ includeTransactions: true, watch: true })` the first result
holds full `Transaction` objects, but as soon as a new block arrives the
cached data is replaced by a block whose `transactions` is an array of hash
strings, while the return type still says `Transaction[]`. The same mismatch
applies to `blockTag: 'safe' | 'finalized'` with `watch`.
Forward both parameters before the `watch` object spread so an explicit
`watch` object still takes precedence. viem resolves both defaults
internally, so forwarding `undefined` keeps the previous behaviour when the
parameters are not set.
|
@Kropiunig is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 9cdca01 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@wagmi/cli
@wagmi/connectors
@wagmi/core
create-wagmi
wagmi
@wagmi/solid
@wagmi/vue
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #5226 +/- ##
===========================================
- Coverage 88.63% 22.40% -66.23%
===========================================
Files 303 222 -81
Lines 2815 2129 -686
Branches 818 651 -167
===========================================
- Hits 2495 477 -2018
- Misses 123 1572 +1449
+ Partials 197 80 -117 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
promiseeuler
left a comment
There was a problem hiding this comment.
While reviewing this fix on commit 9cdca015, I confirmed that forwarding includeTransactions and blockTag before the watch object spread preserves explicit watcher overrides and keeps watched cache updates aligned with the query parameters. The two changed TypeScript files also pass Biome and git show --check is clean.
I could not complete the focused browser test locally: the repository test endpoint returned HTTP 400 for anvil_mine, and the PR currently has failing Verify / Test (3, 4) and Verify / Check jobs. Leaving this as a comment rather than an approval until those required checks are green.
Problem
useBlockbuilds its query key with the caller'sincludeTransactionsandblockTag, but only forwardsconfigandchainIdintouseWatchBlocks:The watcher therefore fetches with viem's defaults (
includeTransactions: false,blockTag: 'latest') and writes that block straight into a query key that promised something else.For
useBlock({ includeTransactions: true, watch: true })this means the initial fetch returns fullTransactionobjects, and then the very next block silently replacesdata.transactionswith an array of hash strings — while the return type still saysTransaction[]. The same mismatch applies toblockTag: 'safe' | 'finalized'combined withwatch.Fix
Forward
blockTagandincludeTransactionsintouseWatchBlocks, placed before thewatchobject spread so an explicitwatchobject still takes precedence:viem's
watchBlocksresolves both defaults internally (includeTransactions_ ?? false,blockTag = 'latest'), so passingundefinedkeeps the current behaviour when the parameters are not set.Test
Added
parameters: watch (includeTransactions)topackages/react/src/hooks/useBlock.test.ts. The existingparameters: watchtest only coverswatch: truewithoutincludeTransactions, so this case was not exercised.On
mainthe new test fails with:With the fix applied it passes.