Skip to content

feat: hydrate session history from backend on mount#250

Open
sharma-sugurthi wants to merge 2 commits intojenkinsci:mainfrom
sharma-sugurthi:feat/frontend-history-hydration
Open

feat: hydrate session history from backend on mount#250
sharma-sugurthi wants to merge 2 commits intojenkinsci:mainfrom
sharma-sugurthi:feat/frontend-history-hydration

Conversation

@sharma-sugurthi
Copy link
Contributor

Fixes #217

What it does

the frontend now calls GET /sessions/{session_id}/message when switching to a session with no local messages, restoring conversation history from the backend.

Changes

File Change
config.ts Added FETCH_HISTORY: 5000 timeout
chatbot.ts Added fetchSessionHistory() - maps backend format (role/content) to frontend Message model (sender/text)
chatbotStorage.ts Switched sessionStorage - localStorage so session data survives tab close
Chatbot.tsx Added hydration useEffect, updated beforeunload to use localStorage

How it works

  1. on mount or session switch, if the active session has no local messages, fetchSessionHistory() is called.
  2. backend returns {role: "human", content: "..."} - mapped to {sender: "user", text: "..."}
  3. messages are hydrated into the session state
  4. localStorage (instead of sessionStorage) ensures the local cache also survives tab close

Fixes jenkinsci#217

The frontend now calls GET /sessions/{session_id}/message when
switching to a session with no local messages, restoring conversation
history from the backend.

Changes:
- config.ts — added FETCH_HISTORY timeout (5s)
- chatbot.ts — added fetchSessionHistory() with role-to-sender mapping
- chatbotStorage.ts — switched sessionStorage to localStorage
- Chatbot.tsx — added hydration useEffect, updated beforeunload to localStorage
@sharma-sugurthi sharma-sugurthi requested a review from a team as a code owner March 5, 2026 15:23
Updated test files to match production code changes:
- Chatbot.test.tsx: added fetchSessionHistory mock, switched
  sessionStorage to localStorage
- chatbotStorage.test.ts: switched sessionStorage to localStorage
@berviantoleo berviantoleo added the enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frontend does not consume GET /sessions/{session_id}/message - history lost on page reload

2 participants