Skip to content

fix(vue): respect emitOnBegin in useWatchBlockNumber - #5225

Open
pucedoteth wants to merge 2 commits into
wevm:mainfrom
pucedoteth:fix-vue-watch-block-number-emit-on-begin
Open

fix(vue): respect emitOnBegin in useWatchBlockNumber#5225
pucedoteth wants to merge 2 commits into
wevm:mainfrom
pucedoteth:fix-vue-watch-block-number-emit-on-begin

Conversation

@pucedoteth

Copy link
Copy Markdown

useWatchBlockNumber in @wagmi/vue discards the caller's emitOnBegin.

Problem

The composable spreads the caller's parameters and then sets the option itself:

const unwatch = watchBlockNumber(config, {
  ...(rest as any),
  chainId,
  onBlockNumber,
  emitOnBegin: true,
})

The literal comes after the spread, so it always wins. Passing emitOnBegin: false has no effect — the current block is still delivered the moment the watcher subscribes, before anything is mined.

It isn't an internal knob. WatchBlockNumberParameters in @wagmi/core extends viem's, which declares emitOnBegin?: boolean | undefined, so it is part of the public type and compiles fine today:

useWatchBlockNumber({ emitOnBegin: false, onBlockNumber() {} }) // type-checks, silently ignored

The other bindings treat it as caller-controlled:

  • React's useWatchBlockNumber lists rest.emitOnBegin in its effect dependencies (packages/react/src/hooks/useWatchBlockNumber.ts:67), as does useWatchBlocks
  • Solid's tests pass emitOnBegin explicitly

So the same parameters behave differently depending on which binding you use. useWatchContractEvent in Vue doesn't do this — it's specific to this composable.

Change

Destructure emitOnBegin alongside the other options, keeping true as the default:

const {
  chainId = configChainId.value,
  emitOnBegin = true,
  enabled = true,
  ...
} = parameters.value

I kept the existing true default deliberately, so nothing changes for callers who don't pass the option — only an explicit value now reaches viem. Worth flagging that this leaves Vue defaulting to true while React and viem default to false; aligning those would be a behaviour change for existing Vue users, so I left that call to you.

Tests

Added a case to packages/vue/src/composables/useWatchBlockNumber.test.ts asserting emitOnBegin: false produces no callback until a block is actually mined. It fails on main (the callback fires immediately) and passes with the change.

Verification

  • biome check — clean on both files; the repo's pre-commit ran biome check --write across all 1241 files with no fixes applied
  • tsc --noEmit on packages/vue — clean
  • Confirmed emitOnBegin: false type-checks against the composable's public parameter type

I could not run the test suite. It needs anvil forked from mainnet, and https://eth.merkle.io (the default VITE_MAINNET_FORK_URL) returns 403 from my network, so prool can't start the instances — every test in the file fails at the HTTP transport before reaching any assertion, on a clean checkout too. The new test is written against the existing harness and follows the style of the neighbouring parameters: enabled cases, but it needs a CI run to confirm.

The composable spread the caller's parameters and then set emitOnBegin
itself:

    watchBlockNumber(config, {
      ...(rest as any),
      chainId,
      onBlockNumber,
      emitOnBegin: true,
    })

Because the literal comes after the spread it wins, so `emitOnBegin` is
discarded no matter what the caller passes. The option is part of the
public type - wagmi's WatchBlockNumberParameters extends viem's, which
declares `emitOnBegin?: boolean` - and the other bindings honour it:
useWatchBlockNumber in React lists `rest.emitOnBegin` in its effect
dependencies, and the Solid tests pass it explicitly.

A Vue caller asking for `emitOnBegin: false` still gets the current block
delivered the moment the watcher subscribes.

Destructure it with the existing `true` default so behaviour is unchanged
for callers that don't pass it, and an explicit value now reaches viem.
@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f69a9ce

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

This PR includes changesets to release 1 package
Name Type
@wagmi/vue 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

@vercel

vercel Bot commented Aug 19, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

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