fix(react): forward includeTransactions and blockTag to useBlock watcher - #5226
Open
Kropiunig wants to merge 1 commit into
Open
fix(react): forward includeTransactions and blockTag to useBlock watcher#5226Kropiunig wants to merge 1 commit into
Kropiunig 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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.