Skip to content

fix(react): forward includeTransactions and blockTag to useBlock watcher - #5226

Open
Kropiunig wants to merge 1 commit into
wevm:mainfrom
Kropiunig:fix/use-block-watch-forward-params
Open

fix(react): forward includeTransactions and blockTag to useBlock watcher#5226
Kropiunig wants to merge 1 commit into
wevm:mainfrom
Kropiunig:fix/use-block-watch-forward-params

Conversation

@Kropiunig

@Kropiunig Kropiunig commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Problem

useBlock builds its query key with the caller's includeTransactions and blockTag, but only forwards config and chainId into useWatchBlocks:

const options = getBlockQueryOptions(config, {
  ...parameters,
  chainId: parameters.chainId ?? chainId,
})
useWatchBlocks({
  ...({
    config: parameters.config,
    chainId: parameters.chainId!,
    ...(typeof parameters.watch === 'object' ? parameters.watch : {}),
  } as UseWatchBlocksParameters),
  ...
  onBlock(block) {
    queryClient.setQueryData(options.queryKey, block)
  },
})

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 full Transaction objects, and then the very next block silently replaces data.transactions with an array of hash strings — while the return type still says Transaction[]. The same mismatch applies to blockTag: 'safe' | 'finalized' combined with watch.

Fix

Forward blockTag and includeTransactions into useWatchBlocks, placed before the watch object spread so an explicit watch object still takes precedence:

blockTag: parameters.blockTag,
includeTransactions: parameters.includeTransactions,

viem's watchBlocks resolves both defaults internally (includeTransactions_ ?? false, blockTag = 'latest'), so passing undefined keeps the current behaviour when the parameters are not set.

Test

Added parameters: watch (includeTransactions) to packages/react/src/hooks/useBlock.test.ts. The existing parameters: watch test only covers watch: true without includeTransactions, so this case was not exercised.

On main the new test fails with:

AssertionError: expected 'string' not to be 'string'
 at packages/react/src/hooks/useBlock.test.ts:98:37

With the fix applied it passes.

`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.
@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

@Kropiunig is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9cdca01

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wagmi Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Aug 20, 2026

Copy link
Copy Markdown

Open in StackBlitz

@wagmi/cli

npm i https://pkg.pr.new/@wagmi/cli@5226

@wagmi/connectors

npm i https://pkg.pr.new/@wagmi/connectors@5226

@wagmi/core

npm i https://pkg.pr.new/@wagmi/core@5226

create-wagmi

npm i https://pkg.pr.new/create-wagmi@5226

wagmi

npm i https://pkg.pr.new/wagmi@5226

@wagmi/solid

npm i https://pkg.pr.new/@wagmi/solid@5226

@wagmi/vue

npm i https://pkg.pr.new/@wagmi/vue@5226

commit: 9cdca01

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 22.40%. Comparing base (b7d4c11) to head (9cdca01).

❗ There is a different number of reports uploaded between BASE (b7d4c11) and HEAD (9cdca01). Click for more details.

HEAD has 4 uploads less than BASE
Flag BASE (b7d4c11) HEAD (9cdca01)
7 3
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant