Commit d3ee37a
fix(frontend): restore chat history when returning to a session (#1684)
## Summary
- Replace async `params.then()` + `useState` with synchronous
`React.use(params)` so route params are available from the first render
- Eliminates a race condition where the AG-UI EventSource connection was
deferred to a second render cycle, causing historical SSE events (chat
history) to be missed on re-navigation
- Simplifies `backHref` extraction from URL search params using
`useMemo` instead of `useState`
## Root Cause
The session detail page extracted `projectName` and `sessionName` from
the async `params` Promise via `useEffect(() => { params.then(...) })`,
initializing both as empty strings. This meant:
1. **First render**: empty strings → connection effect skipped (guard
clause `if (\!projectName || \!sessionName) return`)
2. **Params resolve** → `setState` triggers re-render
3. **Second render**: correct values → connection effect fires via
`aguiConnectRef`
On fast re-navigation (navigate away, come back), this timing gap could
cause the EventSource to miss the backend's SSE replay of historical
events, resulting in an empty chat view despite the conversation context
being intact on the backend.
## Test plan
- [ ] Navigate to a session with existing messages, verify chat history
loads
- [ ] Navigate away from the session (click sidebar, go to sessions
list)
- [ ] Navigate back to the same session, verify chat history is still
visible
- [ ] Repeat with rapid back-and-forth navigation
- [ ] Verify new messages can still be sent and received after
re-navigation
- [ ] `npm run build` passes with 0 errors, 0 warnings
- [ ] `npx tsc --noEmit` passes
- [ ] ESLint passes on changed file
🤖 Generated with [Claude Code](https://claude.ai/code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Optimized session detail page loading logic for improved performance
and reliability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Co-authored-by: user <u@example.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>1 parent 8e3bac3 commit d3ee37a
1 file changed
Lines changed: 12 additions & 18 deletions
Lines changed: 12 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
121 | | - | |
122 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
123 | 129 | | |
124 | 130 | | |
125 | 131 | | |
| |||
148 | 154 | | |
149 | 155 | | |
150 | 156 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | 157 | | |
164 | 158 | | |
165 | 159 | | |
| |||
208 | 202 | | |
209 | 203 | | |
210 | 204 | | |
211 | | - | |
212 | | - | |
| 205 | + | |
| 206 | + | |
213 | 207 | | |
214 | 208 | | |
215 | 209 | | |
| |||
0 commit comments