fix(ui): stabilize authenticated page requests

This commit is contained in:
jxxghp
2026-08-13 07:20:49 +08:00
parent 0ea12f75f7
commit 2b0325e02b
13 changed files with 75 additions and 27 deletions
@@ -8,6 +8,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
interface RequestConfigFake {
signal?: AbortSignal
skipNavigationCancellation?: boolean
}
interface ResponseFake {
@@ -119,6 +120,19 @@ describe('requestOptimizer', () => {
expect(getActiveRequestsCount()).toBe(0)
})
it('不把跨路由心跳和轮询纳入导航取消', () => {
const interceptors = createAxiosInterceptorFake()
const config = interceptors.request.fulfilled({ skipNavigationCancellation: true })
expect(config.signal).toBeUndefined()
expect(getActiveRequestsCount()).toBe(0)
setNavigatingState(true)
expect(config.signal).toBeUndefined()
expect(getActiveRequestsCount()).toBe(0)
})
it('导航开始时只取消当前活跃请求,导航结束不主动取消', () => {
const interceptors = createAxiosInterceptorFake()
const first = interceptors.request.fulfilled({})
+2 -2
View File
@@ -35,8 +35,8 @@ export function initializeRequestOptimizer(axiosInstance: any) {
// 拦截请求,自动添加 AbortController
axiosInstance.interceptors.request.use(
(config: any) => {
// 如果请求已经有 signal,跳过(避免覆盖手动设置的)
if (config.signal) {
// 心跳与轮询不属于页面生命周期,路由切换时应继续完成。
if (config.signal || config.skipNavigationCancellation) {
return config
}