mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-01 13:36:43 +08:00
fix(ui): stabilize authenticated page requests
This commit is contained in:
@@ -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({})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user