Skip to content

fix: clear observe caches after unwatch#4630

Merged
jxom merged 1 commit into
mainfrom
jxom/fix-observe-cache-cleanup
May 18, 2026
Merged

fix: clear observe caches after unwatch#4630
jxom merged 1 commit into
mainfrom
jxom/fix-observe-cache-cleanup

Conversation

@jxom
Copy link
Copy Markdown
Member

@jxom jxom commented May 18, 2026

Clears observe listener and cleanup cache entries once the final listener unsubscribes. This prevents short-lived watchers from retaining empty listener arrays and stale cleanup closures after watchBlockNumber or similar observers are torn down.

Adds regression coverage for final unwatch cache deletion and for a later observer not reusing the previous cleanup. Validated with SKIP_GLOBAL_SETUP=true pnpm test src/utils/observe.test.ts and pnpm exec biome check src/utils/observe.ts src/utils/observe.test.ts.

Closes #4390

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 18, 2026

🦋 Changeset detected

Latest commit: 9a6e2c2

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

This PR includes changesets to release 1 package
Name Type
viem 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
Copy link
Copy Markdown

vercel Bot commented May 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
viem Ready Ready Preview, Comment May 18, 2026 0:27am

Request Review

@jxom jxom marked this pull request as ready for review May 18, 2026 00:26
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 18, 2026

Open in StackBlitz

npm i https://pkg.pr.new/viem@4630

commit: 9a6e2c2

@jxom jxom merged commit e8bc0fb into main May 18, 2026
28 of 33 checks passed
@jxom jxom deleted the jxom/fix-observe-cache-cleanup branch May 18, 2026 00:28
@github-actions github-actions Bot mentioned this pull request May 18, 2026
@tmm tmm mentioned this pull request May 26, 2026
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.

observe() leaks empty arrays in listenersCache after all listeners unsubscribe

1 participant