langchain-ai / open-canvas

📃 A better UX for chat, writing content, and coding with LLMs.
https://opencanvas.langchain.com/
MIT License
2.58k stars 377 forks source link

Thread persistence: Maintain thread state across page refreshes using URL #177

Open ahmad2b opened 1 week ago

ahmad2b commented 1 week ago

Problem

When users refresh the page by accident, they lose their current thread. This can be frustrating because they have to:

This happens every time the page refreshes because we use useState to store the threadId.

Solution

Let's fix this by using the URL to keep track of active threadId. For example:

Why this matters

Technical Approach

  1. Add a simple URL pattern like /thread/<thread_id>
  2. On initial load, check the URL for thread_id
  3. If thread_id exists, load the corresponding thread
  4. Update the URL whenever users switch threads

Questions