fix(vue): respect emitOnBegin in useWatchBlockNumber - #5225
Open
pucedoteth wants to merge 2 commits into
Open
Conversation
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 detectedLatest commit: f69a9ce 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 |
|
@pucedoteth is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
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.
useWatchBlockNumberin@wagmi/vuediscards the caller'semitOnBegin.Problem
The composable spreads the caller's parameters and then sets the option itself:
The literal comes after the spread, so it always wins. Passing
emitOnBegin: falsehas no effect — the current block is still delivered the moment the watcher subscribes, before anything is mined.It isn't an internal knob.
WatchBlockNumberParametersin@wagmi/coreextends viem's, which declaresemitOnBegin?: boolean | undefined, so it is part of the public type and compiles fine today:The other bindings treat it as caller-controlled:
useWatchBlockNumberlistsrest.emitOnBeginin its effect dependencies (packages/react/src/hooks/useWatchBlockNumber.ts:67), as doesuseWatchBlocksemitOnBeginexplicitlySo the same parameters behave differently depending on which binding you use.
useWatchContractEventin Vue doesn't do this — it's specific to this composable.Change
Destructure
emitOnBeginalongside the other options, keepingtrueas the default:I kept the existing
truedefault 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 totruewhile React and viem default tofalse; 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.tsassertingemitOnBegin: falseproduces no callback until a block is actually mined. It fails onmain(the callback fires immediately) and passes with the change.Verification
biome check— clean on both files; the repo's pre-commit ranbiome check --writeacross all 1241 files with no fixes appliedtsc --noEmitonpackages/vue— cleanemitOnBegin: falsetype-checks against the composable's public parameter typeI could not run the test suite. It needs anvil forked from mainnet, and
https://eth.merkle.io(the defaultVITE_MAINNET_FORK_URL) returns 403 from my network, soproolcan'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 neighbouringparameters: enabledcases, but it needs a CI run to confirm.