Просмотр исходного кода

fix: 刷新后恢复路由会话内容

samien 2 месяцев назад
Родитель
Сommit
6afe7df926
2 измененных файлов с 18 добавлено и 3 удалено
  1. 6 2
      src/client/views/ChatView.vue
  2. 12 1
      tests/e2e/workspace.spec.ts

+ 6 - 2
src/client/views/ChatView.vue

@@ -73,9 +73,13 @@ const reasoningComposerOptions = computed<ComposerOption[]>(() => reasoningOptio
 const reasoningLabel = computed(() => reasoningOptions.find(option => option.id === (chat.reasoningEffort || ''))?.label || '默认')
 
 async function refreshSessions() {
-  await Promise.all([chat.loadSessions(auth.activeProfile?.name), chat.loadUnread(auth.activeProfile?.name)])
+  const profile = auth.activeProfile?.name
+  // The session route is the authoritative navigation target. A secondary
+  // unread-count request must never prevent its history from being restored.
+  await chat.loadSessions(profile)
   const requestedId = typeof route.params.sessionId === 'string' ? route.params.sessionId : ''
-  if (requestedId && chat.activeSessionId !== requestedId) await chat.selectSession(requestedId, auth.activeProfile?.name)
+  if (requestedId && chat.activeSessionId !== requestedId) await chat.selectSession(requestedId, profile)
+  void chat.loadUnread(profile).catch(() => undefined)
 }
 
 async function chooseSession(id: string) {

+ 12 - 1
tests/e2e/workspace.spec.ts

@@ -39,6 +39,17 @@ test('navigates every 9119 workspace without blank transitions', async ({ page }
   expect(consoleErrors).toEqual([])
 })
 
+test('restores a routed conversation even when unread-count refresh fails', async ({ page }) => {
+  await page.route('**/api/app/sessions/unread*', async route => {
+    await route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'unread unavailable' }) })
+  })
+
+  await page.goto('/chat/session-demo')
+  await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
+  await page.reload()
+  await expect(page.getByText('已整理完成。下面是', { exact: false })).toBeVisible()
+})
+
 test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ page }) => {
   const logo = page.locator('.rail__brand img')
   await expect(logo).toHaveAttribute('src', '/brand/AppIcon-1024.png')
@@ -54,7 +65,7 @@ test('keeps the canonical logo and yaoyao-webui composer geometry', async ({ pag
   await expect(page.getByText('语音输入设置', { exact: true })).toBeVisible()
   await page.locator('.composer-shell').click()
   await page.getByRole('option').first().click()
-  await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(245, 248, 252)')
+  await expect(page.locator('.timeline')).toHaveCSS('background-color', 'rgb(255, 255, 255)')
   await expect(page.locator('.message--user .message__meta')).toHaveCSS('display', 'none')
   await expect(page.getByRole('button', { name: '会话操作' })).toBeVisible()
   await page.getByRole('button', { name: '会话操作' }).click()