fix: scope retry cache cleanup to interwovenkit queries#169
fix: scope retry cache cleanup to interwovenkit queries#169simcheolhwan merged 3 commits intomainfrom
Conversation
WalkthroughIntroduces a new utility function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Deploying interwovenkit with
|
| Latest commit: |
d811e9f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d1c32f92.interwovenkit.pages.dev |
| Branch Preview URL: | https://fix-scope-interwovenkit-quer.interwovenkit.pages.dev |
Deploying interwovenkit-testnet with
|
| 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 |
Deploying interwovenkit-staging with
|
| 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 |
- walletconnect-wallets → interwovenkit:walletconnect-wallets - erc20-approvals-needed → interwovenkit:erc20-approvals-needed - update test to assert prefixed keys are cleared
There was a problem hiding this comment.
🧹 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
📒 Files selected for processing (5)
packages/interwovenkit-react/src/data/query-client.test.tspackages/interwovenkit-react/src/data/query-client.tspackages/interwovenkit-react/src/pages/bridge/FooterWithErc20Approval.tsxpackages/interwovenkit-react/src/pages/connect/useWalletConnectWallets.tspackages/interwovenkit-react/src/public/app/Drawer.tsx
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
DrawerusedqueryClient.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:
clearInterwovenKitQueries(queryClient)insrc/data/query-client.tsinterwovenkit:queryClient.clear()with the scoped cleanup helper insrc/public/app/Drawer.tsxMotivation
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 scopedclearInterwovenKitQueries(queryClient).Introduces
clearInterwovenKitQueriesindata/query-client.ts, which removes only queries whosequeryKeystarts with theinterwovenkit: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
Tests