Files
fusion/packages/dashboard/app/hooks/chatPendingMessageStorage.ts
gsxdsm 70e7a6b30a FN-5852: persist queued chat messages across navigation
Keep queued follow-up chat drafts across session switches, reloads, and view re-entry.

- persist queued pending-message text per chat session in shared localStorage helpers
- restore and flush queued follow-up messages in full Chat when returning to an active session
- restore and flush queued follow-up messages in Quick Chat and cover the recovery path with tests
- document queued-message persistence behavior in the dashboard guide

Files changed:
 docs/dashboard-guide.md                            |   2 +
 .../dashboard/app/hooks/__tests__/useChat.test.ts  | 119 +++++++++++++++++-
 .../app/hooks/__tests__/useQuickChat.test.ts       | 135 +++++++++++++++++++++
 .../app/hooks/chatPendingMessageStorage.ts         |  48 ++++++++
 packages/dashboard/app/hooks/useChat.ts            |  38 ++++++
 packages/dashboard/app/hooks/useQuickChat.ts       |  35 ++++++
 6 files changed, 376 insertions(+), 1 deletion(-)

Fusion-Task-Id: FN-5852

Fusion-Task-Lineage: 1cddfb19-7e02-40e5-b373-5d593dfcfe2a
2026-06-01 22:11:30 -07:00

49 lines
1.2 KiB
TypeScript

const CHAT_PENDING_MESSAGE_STORAGE_PREFIX = "fusion:chat-pending:";
export function getChatPendingMessageKey(sessionId: string | null | undefined): string | null {
if (!sessionId) {
return null;
}
return `${CHAT_PENDING_MESSAGE_STORAGE_PREFIX}${sessionId}`;
}
export function getPersistedPendingChatMessage(sessionId: string | null | undefined): string {
const key = getChatPendingMessageKey(sessionId);
if (!key || typeof window === "undefined") {
return "";
}
try {
return localStorage.getItem(key) ?? "";
} catch {
return "";
}
}
export function setPersistedPendingChatMessage(sessionId: string | null | undefined, content: string): void {
const key = getChatPendingMessageKey(sessionId);
if (!key || typeof window === "undefined") {
return;
}
try {
localStorage.setItem(key, content);
} catch {
// Ignore localStorage failures so chat queuing still works in-memory.
}
}
export function removePersistedPendingChatMessage(sessionId: string | null | undefined): void {
const key = getChatPendingMessageKey(sessionId);
if (!key || typeof window === "undefined") {
return;
}
try {
localStorage.removeItem(key);
} catch {
// Ignore localStorage failures so cleanup paths do not throw.
}
}