fix: resolve client-side error when re-selecting newly created tag#3691
fix: resolve client-side error when re-selecting newly created tag#3691MaanLad wants to merge 2 commits intodubinc:mainfrom
Conversation
|
@MaanLad is attempting to deploy a commit to the Dub Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThe change improves cache synchronization after tag creation by implementing selective SWR cache updates. Instead of revalidating a single query key, it now targets all relevant tag query variants, properly revalidates base queries, strategically refreshes search-filtered queries, and prepends newly created tags into the cached data structure. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/web/ui/links/link-builder/tag-select.tsx (1)
80-89: Good approach for selective cache mutation; minor simplification possible.The strategy to mutate only base queries (non-search keys and empty-search keys) while skipping active search queries is sound and aligns with the fix goals.
One minor redundancy: on line 85, since we only reach this line when
key.includes("search=")is true (line 84 didn't returntrue), the first part of the condition is always satisfied. You could simplify to justreturn key.includes("search=&");.🧹 Optional simplification
await mutate( (key) => { if (typeof key !== "string") return false; if (!key.startsWith(`/api/tags?workspaceId=${workspaceId}`)) return false; if (!key.includes("search=")) return true; - return key.includes("search=") && key.includes("search=&"); // Only base query + return key.includes("search=&"); // Only base query (empty search) }, (data) => (data ? [newTag, ...data] : [newTag]), false );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/ui/links/link-builder/tag-select.tsx` around lines 80 - 89, The key-filtering predicate passed to mutate can be simplified: inside the mutate call (the predicate that checks cache keys for `/api/tags?workspaceId=${workspaceId}`) remove the redundant check and instead, after ensuring key includes "search=", return only key.includes("search=&"); keep the surrounding checks for typeof key and startsWith(`/api/tags?workspaceId=${workspaceId}`) and leave the updater that prepends newTag unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/ui/links/link-builder/tag-select.tsx`:
- Around line 80-89: The key-filtering predicate passed to mutate can be
simplified: inside the mutate call (the predicate that checks cache keys for
`/api/tags?workspaceId=${workspaceId}`) remove the redundant check and instead,
after ensuring key includes "search=", return only key.includes("search=&");
keep the surrounding checks for typeof key and
startsWith(`/api/tags?workspaceId=${workspaceId}`) and leave the updater that
prepends newTag unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a8dd980a-7e9f-47f3-8b80-e29dfe407818
📒 Files selected for processing (1)
apps/web/ui/links/link-builder/tag-select.tsx
Fix: Client-side error when re-selecting newly created tag
Summary
Fixes a client-side error that occurs when a newly created tag is unselected and then selected again.
Root Cause
tag-selectand@dub/uiComboBoxuseTagsmutation was updating both base and search queries, leading to inconsistent dataChanges
Behavior
TAGS_MAX_PAGE_SIZE)Result
Tags can now be re-selected without client-side errors.
Issue
Closes #3685
Summary by CodeRabbit