Skip to content

Commit dfcc0fa

Browse files
Remove flagged comments and guard early-return against empty-page flash
1 parent 65a515f commit dfcc0fa

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

frontend/src/components/session/SessionList.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,23 @@ describe('SessionList', () => {
230230
expect(screen.getByText('Click here to start a new session')).toBeTruthy()
231231
})
232232

233+
it('shows loading state instead of create-session card when the first page is empty but more pages are pending', () => {
234+
sessionsData.splice(0, sessionsData.length)
235+
hasNextPageRef.current = true
236+
237+
render(
238+
<SessionList
239+
opcodeUrl="/api/opencode"
240+
directories={['/w/a']}
241+
onSelectSession={vi.fn()}
242+
/>,
243+
)
244+
245+
expect(screen.getByText('Loading sessions...')).toBeTruthy()
246+
expect(screen.queryByText('No sessions yet')).toBeNull()
247+
expect(screen.queryByText('Click here to start a new session')).toBeNull()
248+
})
249+
233250
it('auto-fetches next page when all visible sessions are filtered out as child sessions', async () => {
234251
sessionsData.splice(0, sessionsData.length,
235252
{ id: 'child1', title: 'child session', directory: '/w/a', parentID: 'parent1', time: { updated: Date.now() } },

frontend/src/components/session/SessionList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ export const SessionList = ({
9898
}
9999

100100
if (!sessions || sessions.length === 0) {
101-
// If user is searching, fall through to main render which shows "No sessions found"
101+
if (hasNextPage || isFetchingNextPage) {
102+
return <div className="p-4 text-sm text-muted-foreground">Loading sessions...</div>;
103+
}
102104
if (!searchQuery.trim()) {
103105
return (
104106
<div className="flex-1 overflow-y-auto overflow-x-hidden px-4 pt-4 pb-4 min-h-0 [mask-image:linear-gradient(to_bottom,transparent,black_16px,black)]">

frontend/src/contexts/EventContext.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
233233
const sessionsData = query.state.data
234234
if (!sessionsData) continue
235235

236-
// Handle legacy Session[] (plain array)
237236
if (Array.isArray(sessionsData)) {
238237
const found = sessionsData.find((s: { id: string }) => s.id === sessionID)
239238
if (found) {
@@ -243,7 +242,6 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
243242
continue
244243
}
245244

246-
// Handle infinite-query InfiniteData<{ items: Session[] }> shape
247245
if (typeof sessionsData === 'object' && 'pages' in sessionsData) {
248246
const infiniteData = sessionsData as { pages: Array<{ items: Array<{ id: string; directory?: string }> }> }
249247
for (const page of infiniteData.pages) {

0 commit comments

Comments
 (0)