-
Notifications
You must be signed in to change notification settings - Fork 3
Add a temporary solution for handling conflicts between the remote state and client-side cache when moving todo items #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ate and client-side cache when moving todo items
WalkthroughRemoves batched/debounced todo-item persistence and the batch API, makes todoItemsCollection generic with a new query key, implements immediate per-item optimistic updates with server PATCH per item, and changes the PATCH API to return a single updated item. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Component as TodoBoards
participant Collection as todoItemsCollection
participant Server as PATCH /api/todo-items
participant UI as Toast/Error Handler
rect rgba(100,150,200,0.12)
note over Component,Collection: Immediate per-item update
User->>Component: Drop item (compute boardId, position)
Component->>Collection: update(itemId, { boardId, position })
Collection->>Collection: Apply optimistic local change
Collection-->>Component: Local state updated
end
Component->>Server: PATCH item
alt Server success
Server-->>Collection: Return updated item
Collection->>Collection: Confirm/retain optimistic state
else Server error
Server-->>Collection: Error
Collection->>UI: Show error toast
Collection->>Server: (optional) refetch latest state
Server-->>Collection: Latest state
Collection->>Collection: Reconcile / rollback
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (3)src/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{tsx,ts}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧬 Code graph analysis (2)src/collections/todoItems.ts (2)
src/local-api/api.todo-items.ts (2)
🔇 Additional comments (5)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/collections/todoItems.ts (1)
38-57: Address the unused export warning.The
batchUpdateTodoItemfunction is exported but never used according to the pipeline failure. Since the PR moves to per-item updates, this appears to be dead code that should either be removed or marked for future use.Consider either:
- Removing the function if it's no longer needed
- Removing the
exportkeyword if it's only used internally- Adding a comment explaining why it's kept for future use
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/collections/todoItems.tssrc/components/TodoBoards.tsxsrc/local-api/api.todo-items.ts
🧰 Additional context used
📓 Path-based instructions (3)
src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Always ensure no formatting/linting issues exist in code - use
pnpm check --fixto automatically fix issues
Files:
src/components/TodoBoards.tsxsrc/local-api/api.todo-items.tssrc/collections/todoItems.ts
**/*.{tsx,ts}
📄 CodeRabbit inference engine (AGENTS.md)
Prefer functions over arrow functions for React components
Files:
src/components/TodoBoards.tsxsrc/local-api/api.todo-items.tssrc/collections/todoItems.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Prefer
typeoverinterfacefor type definitions
Files:
src/components/TodoBoards.tsxsrc/local-api/api.todo-items.tssrc/collections/todoItems.ts
🧠 Learnings (2)
📚 Learning: 2025-12-24T15:25:07.106Z
Learnt from: fulopkovacs
Repo: fulopkovacs/trytanstackdb.com PR: 22
File: src/components/TodoBoards.tsx:63-81
Timestamp: 2025-12-24T15:25:07.106Z
Learning: In Tailwind CSS v4, prefer canonical classes using bg-linear-to-* (e.g., bg-linear-to-b, bg-linear-to-t, bg-linear-to-r) over the older bg-gradient-to-* syntax. This aligns with Tailwind LSP's suggestCanonicalClasses rule. Apply across TSX files (e.g., src/components/*.tsx); replace occurrences of bg-gradient-to-* with the corresponding bg-linear-to-* equivalents and verify gradients visually.
Applied to files:
src/components/TodoBoards.tsx
📚 Learning: 2025-12-28T23:34:13.416Z
Learnt from: fulopkovacs
Repo: fulopkovacs/trytanstackdb.com PR: 32
File: src/components/HomeIntro.tsx:16-25
Timestamp: 2025-12-28T23:34:13.416Z
Learning: In Motion (motion/react), when configuring variant transitions, use delayChildren: stagger(x) to create per-child delays (e.g., delayChildren: stagger(0.2)). This is different from the older API that used a separate staggerChildren property. Apply this guidance to TSX files that declare motion variants (e.g., in src/components/**/*.tsx) and verify that stagger is imported from framer-motion. Ensure transitions reflect the intended stagger timing and that no conflicting delay values override the staggered effect.
Applied to files:
src/components/TodoBoards.tsx
🧬 Code graph analysis (2)
src/components/TodoBoards.tsx (3)
src/collections/todoItems.ts (1)
todoItemsCollection(79-148)src/local-api/api.batch.todo-items.ts (1)
updatedData(11-49)src/components/PriorityRating.tsx (1)
index(33-37)
src/collections/todoItems.ts (1)
src/db/schema.ts (1)
TodoItemRecord(72-72)
🪛 GitHub Actions: CI/CD
src/collections/todoItems.ts
[warning] 38-38: Unused exports: 'batchUpdateTodoItem' is defined but never used. (no-unused-vars)
🔇 Additional comments (5)
src/collections/todoItems.ts (3)
55-56: Type assertion is unavoidable here.The TODO comment about avoiding type casting is noted. Since the API contract is established and validated server-side with Zod schemas, this type assertion is reasonable and safe.
77-81: Good practice: Extracting the query key constant.Defining
todoItemsQueryKeyas a constant and using it in the collection options improves maintainability and makes it easier to reference the same query key elsewhere if needed.
97-144: Remove the manualwriteUpdatecall — it's redundant.The optimistic update is already applied when
collection.update()is called (before the onUpdate handler runs). CallingwriteUpdate()in the success path with identicalchangeshas no effect and adds unnecessary code. Since you're returning{ refetch: false }, the optimistic state already stands after server confirmation. If you need to fetch the latest server state instead, removerefetch: falseand let TanStack handle the sync automatically.src/components/TodoBoards.tsx (2)
307-322: Clean refactoring from batch to per-item updates.The new
updateTodoPositionfunction simplifies the update logic by directly mutating the item through the collection'supdatemethod. The implementation correctly handles both position-only updates and board changes, with error handling delegated to the collection'sonUpdatehandler.
400-404: LGTM: Consistent usage of the new update pattern.All three call sites correctly use
updateTodoPositionwith appropriate parameters for their specific scenarios (empty column drop, same-column reorder, and cross-column move).Also applies to: 427-430, 449-453
🚀 Preview DeploymentStatus: ✅ Ready! Preview URL: Open Preview Commit: Built and deployed successfully |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/local-api/api.todo-items.ts (1)
112-118: Add error handling for when the todo item is not found.The destructuring assumes the update will always find a matching item. If
updatedData.iddoesn't exist in the database,updatedTodoItemDatawill beundefined, causing the endpoint to returnjson(undefined)with a 200 status code instead of a proper error response.🔎 Proposed fix
const [updatedTodoItemData] = await db .update(todoItemsTable) .set(updatedData) .where(eq(todoItemsTable.id, updatedData.id)) .returning(); +if (!updatedTodoItemData) { + return new Response(`Todo item not found`, { status: 404 }); +} + return json(updatedTodoItemData);
🧹 Nitpick comments (1)
src/collections/todoItems.ts (1)
110-110: Log the error for better debugging.The error is caught with
_but not logged, making it harder to debug API failures. This is inconsistent with the error handling in theonInsertcallback (line 72) which logs errors to the console.🔎 Proposed fix
- } catch (_) { + } catch (error) { toast.error(`Failed to update todo item "${original.title}"`); + console.error("Failed to update todo item:", error); // Abort all ongoing sync queries
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/collections/todoItems.tssrc/local-api/api.batch.todo-items.tssrc/local-api/api.todo-items.tssrc/local-api/index.ts
💤 Files with no reviewable changes (2)
- src/local-api/api.batch.todo-items.ts
- src/local-api/index.ts
🧰 Additional context used
📓 Path-based instructions (3)
src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (AGENTS.md)
Always ensure no formatting/linting issues exist in code - use
pnpm check --fixto automatically fix issues
Files:
src/local-api/api.todo-items.tssrc/collections/todoItems.ts
**/*.{tsx,ts}
📄 CodeRabbit inference engine (AGENTS.md)
Prefer functions over arrow functions for React components
Files:
src/local-api/api.todo-items.tssrc/collections/todoItems.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Prefer
typeoverinterfacefor type definitions
Files:
src/local-api/api.todo-items.tssrc/collections/todoItems.ts
🧬 Code graph analysis (2)
src/local-api/api.todo-items.ts (3)
src/db/index.ts (1)
db(13-15)src/db/schema.ts (1)
todoItemsTable(54-70)src/local-api/helpers.ts (1)
json(29-43)
src/collections/todoItems.ts (1)
src/db/schema.ts (1)
TodoItemRecord(72-72)
🔇 Additional comments (2)
src/collections/todoItems.ts (2)
56-60: LGTM! Good refactor to improve type safety and maintainability.The introduction of
todoItemsQueryKeyas a constant and making the collection generic withTodoItemRecordimproves code maintainability and type inference.
76-92: Good documentation of the temporary nature of this solution.The warning about not using this in production and the clear explanation of the update strategy helps reviewers understand the limitations and trade-offs.
Summary by CodeRabbit
Bug Fixes
Improvements
Removals
✏️ Tip: You can customize this high-level summary in your review settings.