Fix 404 errors from premature vote API requests #850
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Preventing 404 errors in vote API requests
This PR fixes an issue where the application was making unnecessary requests to the vote endpoint before any assistant responses existed. These premature API calls were resulting in 404 errors in the console since the chat ID wasn't fully registered yet.
Key change:
components/chat.tsx
to conditionally fetch votes only when assistant responses existmessages.some(m => m.role === 'assistant')
to prevent API calls until there's something that can be voted onBefore this fix, the page was refreshing approximately every 20 seconds and attempting to fetch votes for a chat ID that didn't exist yet, resulting in repeated 404 errors.
Secondary Changes: Code quality improvements
As a separate task, I also applied automated fixes from running:
These are purely syntactic changes that don't affect functionality:
Testing
The changes have been tested and verified:
pnpm build
pnpm lint
Impact
This fix improves the application by: