Fix chat messages not loading on navigation#13
Merged
Conversation
Add useEffect to sync loader data with useChat state when they're out of sync. This fixes a bug where chat messages would not appear when navigating from the home page to the reflect page, likely caused by view transitions or component reuse during SPA navigation.
Preview deployed |
Move the redirect logic for existing entries from a useEffect in the component to the loader using TanStack Router's redirect(). This prevents the component from rendering at all when redirecting, avoiding any flash of content.
- Save user messages directly in handleSendMessage instead of via effect - Simplify assistant message effect to only handle the last message after streaming completes - Reduces effect complexity and makes code flow more direct
Instead of using a sync effect workaround, disable view transitions when navigating to /reflect. This ensures the component fully remounts and useChat properly picks up initialMessages from the loader. Remove the sync effect that was added as a workaround.
The view transition disable didn't conclusively fix the issue. Keep the sync effect as a workaround until root cause is identified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add useEffect to sync loader data with useChat state when they're
out of sync. This fixes a bug where chat messages would not appear
when navigating from the home page to the reflect page, likely caused
by view transitions or component reuse during SPA navigation.