fix: preserve auth on edit regenerate#1634
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ❌ 1❌ Failed checks (1 warning)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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)
hooks/useVercelChat.ts (1)
265-268: Clean implementation that follows the Single Responsibility Principle.The
handleReloadcallback correctly encapsulates the responsibility of fetching fresh auth headers before regeneration. The dependency array is complete, and the pattern is consistent with other message-sending functions in this hook (e.g.,handleSubmit,append,handleSendQueryMessages).One observation:
getHeaders()can reject if the underlyinggetAccessToken()throws (peruseChatTransport.ts:13-16). Currently, no try-catch wraps this call, which is consistent with other usages in this file. The error will propagate to the caller. If you want graceful degradation (e.g., showing a toast on auth failure), you could wrap this in a try-catch similar to:💡 Optional: Add error handling for auth failures
const handleReload = useCallback(async () => { + try { const headers = await getHeaders(); await regenerate({ body: chatRequestBody, headers }); + } catch (e) { + console.error("Failed to reload message", e); + toast.error("Failed to reload message. Please try again."); + } }, [getHeaders, regenerate, chatRequestBody]);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@hooks/useVercelChat.ts` around lines 265 - 268, Wrap the getHeaders() call inside handleReload in a try-catch to gracefully handle auth failures (since getHeaders can reject when getAccessToken throws); on catch, call the existing UI error handling (e.g., showToast or setError) and return early instead of letting the error propagate to the caller, then call regenerate({ body: chatRequestBody, headers }) only on success—update the handleReload function to reference getHeaders, regenerate, chatRequestBody, and getAccessToken accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@hooks/useVercelChat.ts`:
- Around line 265-268: Wrap the getHeaders() call inside handleReload in a
try-catch to gracefully handle auth failures (since getHeaders can reject when
getAccessToken throws); on catch, call the existing UI error handling (e.g.,
showToast or setError) and return early instead of letting the error propagate
to the caller, then call regenerate({ body: chatRequestBody, headers }) only on
success—update the handleReload function to reference getHeaders, regenerate,
chatRequestBody, and getAccessToken accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 20084cd6-fcbb-46e3-8feb-c3284e435697
📒 Files selected for processing (1)
hooks/useVercelChat.ts
|
https://jam.dev/c/24e5e2ba-8721-4a6d-99ce-10ff31ce8e14 |
Browser Test: Edit Message → Regenerate with Auth HeadersTested on preview: Test Steps
Result: PASS ✅The edit triggered the following sequence (verified via Chrome DevTools network inspection):
Key VerificationThe regenerate request (
Before this fixThe regenerate call after editing could run without auth headers, causing unauthorized (401) chat requests. This is now fixed — 🤖 Generated with Claude Code using Chrome DevTools MCP |
Summary
Why
Editing a message deletes trailing messages correctly, but the following regenerate call could run without auth headers, causing unauthorized chat requests.
Summary by CodeRabbit