Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughChat UI styling was adjusted (chat-bubble now wraps ChatInterface in a white container and uses an inset 1px border), embedded-chat had its outer shadow removed, and ticket-upload refactored file handling to append files directly and perform per-entry upload status updates. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
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)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/web/ui/support/ticket-upload.tsx (1)
88-121: Uploads may start for files that get discarded.The
addFilesfunction starts uploads for all valid entries (up to MAX_FILES from incoming files) before the state update slices the combined array.Example scenario: If 3 files already exist and user drops 4 valid files:
- Line 95:
validcontains all 4 (sliced to MAX_FILES from incoming only)- Lines 107-119: Uploads start for all 4 entries
- Line 105: Combined array
[...prev(3), ...entries(4)]is sliced to 5, discarding 2 entries- The 2 discarded entries still complete their uploads, but the guard at line 110 correctly prevents state corruption
This wastes network requests for files that won't be kept. Consider calculating the allowed count upfront:
♻️ Proposed fix to avoid wasted uploads
const addFiles = useCallback((incoming: File[]) => { + setFiles((prev) => { + const remaining = MAX_FILES - prev.length; + if (remaining <= 0) return prev; + - const valid = incoming + const valid = incoming - .filter((f) => { + .filter((f) => { - if (!ACCEPTED_TYPES.includes(f.type)) return false; + if (!ACCEPTED_TYPES.includes(f.type)) return false; - if (f.size > MAX_FILE_SIZE_BYTES) return false; + if (f.size > MAX_FILE_SIZE_BYTES) return false; - return true; + return true; - }) + }) - .slice(0, MAX_FILES); + .slice(0, remaining); - if (valid.length === 0) return; + if (valid.length === 0) return prev; - const entries: FileEntry[] = valid.map((file) => ({ + const entries: FileEntry[] = valid.map((file) => ({ - id: `${file.name}-${file.size}-${Date.now()}-${Math.random()}`, + id: `${file.name}-${file.size}-${Date.now()}-${Math.random()}`, - file, + file, - status: "uploading", + status: "uploading", - })); + })); - setFiles((prev) => [...prev, ...entries].slice(0, MAX_FILES)); + // Start uploads after we know which entries will be kept + entries.forEach((entry) => { + uploadToPlain(entry.file).then((result) => { + setFiles((p) => { + if (!p.some((f) => f.id === entry.id)) return p; + return p.map((f) => + f.id === entry.id + ? "error" in result + ? { ...f, status: "error", errorMessage: result.error } + : { ...f, status: "done", attachmentId: result.attachmentId } + : f, + ); + }); + }); + }); - entries.forEach((entry) => { - uploadToPlain(entry.file).then((result) => { - setFiles((prev) => { - if (!prev.some((f) => f.id === entry.id)) return prev; - return prev.map((f) => - f.id === entry.id - ? "error" in result - ? { ...f, status: "error", errorMessage: result.error } - : { ...f, status: "done", attachmentId: result.attachmentId } - : f, - ); - }); - }); + return [...prev, ...entries]; }); }, []);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/ui/support/ticket-upload.tsx` around lines 88 - 121, The addFiles flow currently starts uploads for all generated entries before trimming against MAX_FILES; change it to compute allowed slots from current state and only start uploads for the entries that will actually be added. Inside addFiles, use the setFiles functional updater to read prev.length, compute allowed = Math.max(0, MAX_FILES - prev.length), slice entries to keptEntries = entries.slice(0, allowed), append only keptEntries to prev, and then call uploadToPlain only for keptEntries (not for all entries). Update references: addFiles, entries, setFiles, uploadToPlain, MAX_FILES so discarded files never trigger network uploads.
🤖 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/support/ticket-upload.tsx`:
- Around line 88-121: The addFiles flow currently starts uploads for all
generated entries before trimming against MAX_FILES; change it to compute
allowed slots from current state and only start uploads for the entries that
will actually be added. Inside addFiles, use the setFiles functional updater to
read prev.length, compute allowed = Math.max(0, MAX_FILES - prev.length), slice
entries to keptEntries = entries.slice(0, allowed), append only keptEntries to
prev, and then call uploadToPlain only for keptEntries (not for all entries).
Update references: addFiles, entries, setFiles, uploadToPlain, MAX_FILES so
discarded files never trigger network uploads.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 373de2c1-3ca1-433d-be00-f9bf6442c12b
📒 Files selected for processing (3)
apps/web/ui/support/chat-bubble.tsxapps/web/ui/support/embedded-chat.tsxapps/web/ui/support/ticket-upload.tsx
Summary by CodeRabbit
Style
Bug Fixes