Skip to content

fix: scope retry cache cleanup to interwovenkit queries#169

Merged
simcheolhwan merged 3 commits intomainfrom
fix/scope-interwovenkit-query-cleanup
Feb 25, 2026
Merged

fix: scope retry cache cleanup to interwovenkit queries#169
simcheolhwan merged 3 commits intomainfrom
fix/scope-interwovenkit-query-cleanup

Conversation

@tansawit
Copy link
Contributor

@tansawit tansawit commented Feb 18, 2026

Summary

When a widget request failed and the user retried from the drawer error fallback, the retry path cleared the entire shared React Query cache. In host applications that reuse a single QueryClient, this could evict unrelated app data and force unnecessary refetches outside InterwovenKit.

Root Cause

The retry handler in Drawer used queryClient.clear(), which removes all queries and mutations in the client, not just InterwovenKit-owned cache entries.

Change

This PR scopes cleanup to InterwovenKit-managed queries only:

  • adds clearInterwovenKitQueries(queryClient) in src/data/query-client.ts
  • identifies InterwovenKit entries by query key namespace prefix interwovenkit:
  • replaces queryClient.clear() with the scoped cleanup helper in src/public/app/Drawer.tsx
  • adds a regression test to ensure InterwovenKit queries are removed while host-app queries remain intact

Motivation

InterwovenKit should not mutate host-app cache state beyond its own namespace. Scoping cleanup preserves host application stability and avoids side effects in shared QueryClient setups while keeping the retry behavior intact for widget data.


Note

Low Risk
Small, well-scoped cache-key and cleanup changes; risk is limited to potentially leaving behind or over-removing queries if any InterwovenKit keys aren’t consistently prefixed.

Overview
Prevents the widget’s retry flow from wiping host application React Query state by replacing queryClient.clear() with a scoped clearInterwovenKitQueries(queryClient).

Introduces clearInterwovenKitQueries in data/query-client.ts, which removes only queries whose queryKey starts with the interwovenkit: namespace, and adds a regression test to ensure non-InterwovenKit cache entries remain.

Updates a couple of query keys (e.g. ERC20 approvals and WalletConnect wallets) to use the interwovenkit: prefix so they are included in the scoped cleanup.

Written by Cursor Bugbot for commit d811e9f. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error recovery by selectively clearing only application-related cached data instead of all cached data, preserving user data from unrelated operations.
  • Tests

    • Added test coverage for cache clearing functionality to ensure only relevant data is removed during error recovery.

@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

Walkthrough

Introduces a new utility function clearInterwovenKitQueries to selectively remove InterwovenKit-related query cache entries from TanStack React Query's QueryClient. Updates all InterwovenKit query keys to use a consistent "interwovenkit:" namespace prefix and replaces a broad queryClient.clear() call with targeted cache cleanup.

Changes

Cohort / File(s) Summary
Query Cache Utility
packages/interwovenkit-react/src/data/query-client.ts, packages/interwovenkit-react/src/data/query-client.test.ts
New utility function clearInterwovenKitQueries that removes only InterwovenKit-prefixed queries while preserving unrelated cache entries. Includes test verifying selective removal logic.
Query Key Namespace Updates
packages/interwovenkit-react/src/pages/bridge/FooterWithErc20Approval.tsx, packages/interwovenkit-react/src/pages/connect/useWalletConnectWallets.ts
Updated query key constants to use "interwovenkit:" prefix for consistent namespace scoping without functional changes.
Targeted Cache Cleanup
packages/interwovenkit-react/src/public/app/Drawer.tsx
Replaced broad queryClient.clear() with selective clearInterwovenKitQueries(queryClient) in error recovery flow to preserve non-InterwovenKit cached data.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 hops with joy
Queries cleaned with "interwovenkit:" cheer,
Cache keys namespaced, crystal clear!
No more tangled data left to keep,
The Drawer now knows which ones to sweep,
For InterwovenKit's cache so deep! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: scope retry cache cleanup to interwovenkit queries' accurately and concisely describes the primary change: replacing queryClient.clear() with a scoped cleanup function that only removes InterwovenKit-related queries.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/scope-interwovenkit-query-cleanup

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 18, 2026

Deploying interwovenkit with  Cloudflare Pages  Cloudflare Pages

Latest commit: d811e9f
Status: ✅  Deploy successful!
Preview URL: https://d1c32f92.interwovenkit.pages.dev
Branch Preview URL: https://fix-scope-interwovenkit-quer.interwovenkit.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 18, 2026

Deploying interwovenkit-testnet with  Cloudflare Pages  Cloudflare Pages

Latest commit: d811e9f
Status: ✅  Deploy successful!
Preview URL: https://963abbb0.interwovenkit-testnet.pages.dev
Branch Preview URL: https://fix-scope-interwovenkit-quer.interwovenkit-testnet.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 18, 2026

Deploying interwovenkit-staging with  Cloudflare Pages  Cloudflare Pages

Latest commit: d811e9f
Status: ✅  Deploy successful!
Preview URL: https://9af2490e.interwovenkit-staging.pages.dev
Branch Preview URL: https://fix-scope-interwovenkit-quer.interwovenkit-staging.pages.dev

View logs

@tansawit tansawit added type:bug Something isn't working priority:high labels Feb 18, 2026
@tansawit tansawit marked this pull request as ready for review February 25, 2026 07:33
- walletconnect-wallets → interwovenkit:walletconnect-wallets
- erc20-approvals-needed → interwovenkit:erc20-approvals-needed
- update test to assert prefixed keys are cleared
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/interwovenkit-react/src/data/query-client.ts (1)

3-13: Centralize InterwovenKit query-key construction.

Cleanup relies on prefix discipline; duplicated string literals across files increase drift risk. Export a tiny key-builder from this module and reuse it at call sites.

♻️ Proposed refactor
 import type { QueryClient, QueryKey } from "@tanstack/react-query"

 const INTERWOVENKIT_QUERY_KEY_PREFIX = "interwovenkit:"
+export const interwovenKitQueryKey = (key: string, ...rest: unknown[]) =>
+  [`${INTERWOVENKIT_QUERY_KEY_PREFIX}${key}`, ...rest] as const

 function isInterwovenKitQueryKey(queryKey: QueryKey): boolean {
   const [namespace] = queryKey
   return typeof namespace === "string" && namespace.startsWith(INTERWOVENKIT_QUERY_KEY_PREFIX)
 }
// usage examples outside this file
queryKey: interwovenKitQueryKey("erc20-approvals-needed", tx)
export const walletConnectWalletsQueryKey = interwovenKitQueryKey("walletconnect-wallets")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/interwovenkit-react/src/data/query-client.ts` around lines 3 - 13,
The module exposes a hard-coded prefix INTERWOVENKIT_QUERY_KEY_PREFIX and relies
on callers repeating the same string; add and export a small key-builder
function (e.g., interwovenKitQueryKey(namespace: string, ...rest?: any[]):
QueryKey) that returns an array starting with the prefix + namespace so all
query keys are constructed consistently, replace callers to use
interwovenKitQueryKey instead of embedding the prefix, and keep
clearInterwovenKitQueries using the existing isInterwovenKitQueryKey and
INTERWOVENKIT_QUERY_KEY_PREFIX unchanged so removal logic still detects keys
built by the new helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/interwovenkit-react/src/data/query-client.ts`:
- Around line 3-13: The module exposes a hard-coded prefix
INTERWOVENKIT_QUERY_KEY_PREFIX and relies on callers repeating the same string;
add and export a small key-builder function (e.g.,
interwovenKitQueryKey(namespace: string, ...rest?: any[]): QueryKey) that
returns an array starting with the prefix + namespace so all query keys are
constructed consistently, replace callers to use interwovenKitQueryKey instead
of embedding the prefix, and keep clearInterwovenKitQueries using the existing
isInterwovenKitQueryKey and INTERWOVENKIT_QUERY_KEY_PREFIX unchanged so removal
logic still detects keys built by the new helper.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7a8ec2d and d811e9f.

📒 Files selected for processing (5)
  • packages/interwovenkit-react/src/data/query-client.test.ts
  • packages/interwovenkit-react/src/data/query-client.ts
  • packages/interwovenkit-react/src/pages/bridge/FooterWithErc20Approval.tsx
  • packages/interwovenkit-react/src/pages/connect/useWalletConnectWallets.ts
  • packages/interwovenkit-react/src/public/app/Drawer.tsx

@simcheolhwan simcheolhwan merged commit d2404a5 into main Feb 25, 2026
9 checks passed
@simcheolhwan simcheolhwan deleted the fix/scope-interwovenkit-query-cleanup branch February 25, 2026 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:high type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants