Skip to content

[SDK] Fix: evict empty-string cache keys - #9056

Open
zakazaka95 wants to merge 1 commit into
thirdweb-dev:mainfrom
zakazaka95:sdk/fix-lru-empty-key-eviction
Open

zakazaka95 wants to merge 1 commit into
thirdweb-dev:mainfrom
zakazaka95:sdk/fix-lru-empty-key-eviction

Conversation

@zakazaka95

@zakazaka95 zakazaka95 commented Nov 6, 2026 •

Copy link
Copy Markdown

Keep SDK LRU caches within their configured size when the oldest key is an empty string.

The eviction check treated that valid string key as absent. After an empty input was cached, later insertions could leave address or URL validation caches above their size limit.

  • Check iterator completion before deleting the oldest key.
  • Cover empty-key eviction, recency and subsequent insertions.
  • Add a patch changeset.

Validation:

  • Both new tests failed on the original implementation; all four LRU tests pass with the fix.
  • All 19 selected LRU, address and URL utility tests pass. An independent run also passed the four LRU tests.
  • pnpm --filter 'thirdweb...' build, pnpm fix --filter=thirdweb and pnpm lint --filter=thirdweb pass, including declarations, CJS/ESM, Knip and type checking. Biome reports 562 warnings in unchanged code.

The selected tests use the stock Vitest configuration with only its remote-chain-fork global setup disabled in an external temporary harness. The full stock test suite was not run because it starts remote chain forks.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed cache eviction so empty-string keys are properly removed when the cache exceeds its size limit, while recently accessed entries remain available longer.

@zakazaka95
zakazaka95 requested review from a team as code owners November 6, 2026 09:51
@changeset-bot

changeset-bot Bot commented Nov 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4499d94

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

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/wagmi-adapter Patch
wagmi-inapp 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 Nov 6, 2026

Copy link
Copy Markdown

@zakazaka95 is attempting to deploy a commit to the thirdweb Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added packages SDK Involves changes to the thirdweb SDK labels Nov 6, 2026
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The LRU cache now evicts an empty-string key when it is the oldest key. Tests cover eviction and recency updates. A patch changeset describes the fix.

Changes

LRU eviction

Layer / File(s) Summary
Correct eviction for empty-string keys
packages/thirdweb/src/utils/caching/lru.ts, packages/thirdweb/src/utils/caching/lru.test.ts, .changeset/empty-cache-keys-evict.md
LruMap.set checks whether the key iterator is exhausted before deleting its first key. Tests verify that an empty-string key is evicted when oldest and that accessing it refreshes its recency. The changeset describes the patch.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested labels: packages, SDK

Suggested reviewers: 0xfirekeeper

Merge Risk: Minimal · up to 4499d

The cache fix addresses empty-key eviction, with no merge-blocking risk evident.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly describes the main cache eviction fix.
Description check Passed The description explains the fix, test results, and test limitations. It does not use the template headings or include an issue tag.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7312c863-c3c6-4052-b94e-1e57a65c8b82
Commits

Reviewing files that changed from the base of the PR and between 940b374 and 4499d94.

Files selected for processing: 3

  • .changeset/empty-cache-keys-evict.md
  • packages/thirdweb/src/utils/caching/lru.test.ts
  • packages/thirdweb/src/utils/caching/lru.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

packages SDK Involves changes to the thirdweb SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant