Skip to content
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

Fix 404 errors from premature vote API requests #850

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

RMNCLDYO
Copy link

@RMNCLDYO RMNCLDYO commented Mar 7, 2025

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:

  • Modified components/chat.tsx to conditionally fetch votes only when assistant responses exist
  • Added a check using messages.some(m => m.role === 'assistant') to prevent API calls until there's something that can be voted on

Before 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:

pnpm lint
pnpm lint:fix
pnpm format

These are purely syntactic changes that don't affect functionality:

  • Added type annotations to imports
  • Fixed SVG self-closing tags
  • Other standard linting/formatting improvements

Testing

The changes have been tested and verified:

  • Confirmed that no 404 errors appear in the console when starting a new chat
  • Vote API requests only begin after receiving the first assistant response
  • All builds complete successfully with pnpm build
  • No remaining linting issues with pnpm lint

Impact

This fix improves the application by:

  1. Eliminating unnecessary network requests
  2. Removing error messages from the console
  3. Following best practices by only fetching data when it's needed

RMNCLDYO added 2 commits March 7, 2025 11:15
This commit applies automated fixes from running `pnpm lint`, `pnpm lint:fix`, and `pnpm format` using Biome. The changes include:

- Add explicit 'type' annotations to TypeScript imports that are only used for type information
- Fix SVG path elements to use proper self-closing syntax
- Replace deprecated direct fs/path imports with node: prefixed imports
- Remove unused imports
- Use optional chaining for safer conditional rendering
- Fix string quote inconsistency in keyboard event handling
This change modifies the vote API request logic in chat.tsx to only
fetch votes when there are assistant responses that can actually be
voted on. Previously, the app was making requests to the vote endpoint
immediately when a chat was opened, resulting in 404 errors since
the chat ID wasn't fully registered yet.

By conditionally fetching votes only when assistant responses exist,
we eliminate unnecessary API calls and prevent the 404 errors that
were appearing in the console.
Copy link

vercel bot commented Mar 7, 2025

@RMNCLDYO is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant