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

useParams hook not updating when URL changes from root path #734

Open
yoav0gal opened this issue Jan 28, 2025 · 0 comments
Open

useParams hook not updating when URL changes from root path #734

yoav0gal opened this issue Jan 28, 2025 · 0 comments

Comments

@yoav0gal
Copy link

yoav0gal commented Jan 28, 2025

Bug: useParams hook not updating when URL changes from root path

Issue

When starting a new chat from the root path ('/'), the useParams hook in the sidebar doesn't detect the chat ID even after the URL changes to /chat/[id]. This creates a UI inconsistency where the active chat is not highlighted in the sidebar.

Reproduction Steps

  1. Create a user and log-in
  2. Start at root path ('/')
  3. Begin a new chat
  4. Send first message
  5. URL changes to /chat/[id]
  6. Sidebar fails to highlight the active chat because useParams returns undefined.
  7. Sidebar fails to navigate back to root ('/') on the chat deletion.

Technical Details

To my understanding, the issue occurs due to how the chat creation flow works with the useChat hook from Vercel's AI SDK. The URL changes happen without triggering a full route change that useParams would detect.
From my understanding - this might be related to the useSWR, in useChat, but that was 2 deep of a dive for me RN 😆

Workaround

Added a fallback to extract the chat ID from pathname when useParams returns undefined at sidebar-history.tsx:

const pathname = usePathname();
const params = useParams();
const id = params.id ?? pathname.split("/").pop();
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

No branches or pull requests

1 participant