Skip to content

🪤 fix: Reload Messages When Reopening a Chat from a Non-Chat Route#13501

Merged
danny-avila merged 1 commit into
devfrom
fix/project-chat-stale-message-cache
Jun 4, 2026
Merged

🪤 fix: Reload Messages When Reopening a Chat from a Non-Chat Route#13501
danny-avila merged 1 commit into
devfrom
fix/project-chat-stale-message-cache

Conversation

@danny-avila

Copy link
Copy Markdown
Owner

Summary

Fixes a bug where clicking a previously-visited project chat from the sidebar while on the /projects page leaves the chat stuck on a loading spinner — the messages query never fires.

Reproduction

  1. Load /c/new.
  2. Expand a project in the sidebar and open two of its chats (both load fine).
  3. Click All projects to go to /projects.
  4. From the sidebar, click one of the already-visited chats.
  5. The chat never loads — no /api/messages/:id request goes out.

Root cause

When you navigate away from conversation X, clearMessagesCache(X) sets [QueryKeys.messages, X] to [] — a defined-but-empty value, not undefined.

The messages query (useGetMessagesByConvoId) defaults to refetchOnMount: false. When you later return to X via navigateToConvo from a route where ChatRoute was unmounted (e.g. /projects), ChatView mounts fresh, finds the cached [], and — per refetchOnMount: false — never refetches. Result: no network request, messagesTree stays empty, and ChatView shows LoadingSpinner forever.

It only worked when navigating from another /c/:id because the messages observer stayed continuously mounted there, so the query-key change refetched the stale []. From a non-chat route the observer mounts fresh and that recovery never happens — an observer-lifecycle accident that shouldn't be load-bearing.

Fix

navigateToConvo — the single entry point for in-app conversation navigation — now removes the target's messages cache before fetching:

queryClient.removeQueries([QueryKeys.messages, convo.conversationId]);

With the cache undefined, a freshly-mounted ChatView performs an initial fetch regardless of refetchOnMount. This is route-agnostic (works from /projects, search, settings, agent detail — anywhere ChatRoute was unmounted) and doesn't touch clearMessagesCache (removing there would force a wasteful refetch of the outgoing conversation right before it unmounts). It also matches existing behavior — the working case already refetches messages on navigation.

Notes

  • One-line behavioral change; no API or schema changes.
  • A Playwright regression test (mock harness) for the project-sidebar → /projects → reopen flow is a good follow-up.

…t route

navigateToConvo now removes the target conversation's cached messages before
fetching, so a freshly-mounted ChatView refetches them. clearMessagesCache
leaves a left conversation cached as [], and the messages query's
refetchOnMount: false treats that empty array as valid — so returning to the
conversation from a route where ChatRoute was unmounted (e.g. /projects) left
the chat stuck on an empty cache with no /api/messages request.
Copilot AI review requested due to automatic review settings June 4, 2026 03:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a navigation edge case where reopening a previously visited conversation from a non-chat route (e.g. /projects) could leave ChatView stuck on a loading spinner because the messages query never refetched after clearMessagesCache left an empty-but-defined cache ([]).

Changes:

  • Remove the target conversation’s messages query from the React Query cache during navigateToConvo to ensure a fresh mount triggers the initial messages fetch.
  • Add inline documentation explaining why removal (vs invalidation) is required given refetchOnMount: false.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@danny-avila danny-avila changed the title fix: reload messages when reopening a chat from a non-chat route (project sidebar → /projects) 🪤 fix: Reload Messages When Reopening a Chat from a Non-Chat Route Jun 4, 2026
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13501 index is now live on the MCP server.
Deploy run

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila merged commit 45d85bd into dev Jun 4, 2026
11 checks passed
@danny-avila danny-avila deleted the fix/project-chat-stale-message-cache branch June 4, 2026 03:21
fuuuzzy pushed a commit to fuuuzzy/LibreChat that referenced this pull request Jun 4, 2026
…anny-avila#13501)

navigateToConvo now removes the target conversation's cached messages before
fetching, so a freshly-mounted ChatView refetches them. clearMessagesCache
leaves a left conversation cached as [], and the messages query's
refetchOnMount: false treats that empty array as valid — so returning to the
conversation from a route where ChatRoute was unmounted (e.g. /projects) left
the chat stuck on an empty cache with no /api/messages request.
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.

2 participants