From 27e03ae0381ae175aa616f8b729cf37dd7c89cff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=A8=E9=9C=96=E9=93=83?= <2712495353@qq.com> Date: Tue, 30 Jun 2026 22:51:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20RouterContaine?= =?UTF-8?q?r=20=E7=BB=84=E4=BB=B6=E4=B8=AD=E7=9A=84=20isLoaded=20=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 简化 RouterContainer 组件逻辑,直接渲染页面内容,无需等待加载状态。 - 更新测试用例,确保在组件挂载后直接渲染页面结构。 --- src/components/RouterContainer.tsx | 6 +----- .../__tests__/RouterContainer.test.tsx | 17 ++++------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/src/components/RouterContainer.tsx b/src/components/RouterContainer.tsx index 03e51cd..f0465c1 100644 --- a/src/components/RouterContainer.tsx +++ b/src/components/RouterContainer.tsx @@ -37,15 +37,11 @@ function LoadedPage({ pageKey }: { pageKey: PageType }) { } export default function RouterContainer() { - const { currentPage, isLoaded } = useRouter(); + const { currentPage } = useRouter(); const animationClass = currentPage === 'dashboard' ? 'page-transition-dashboard' : 'page-transition-enter'; - if (!isLoaded) { - return ; - } - const currentFeature = getFeatureByKey(currentPage); return ( diff --git a/src/components/__tests__/RouterContainer.test.tsx b/src/components/__tests__/RouterContainer.test.tsx index a913afd..1691e8c 100644 --- a/src/components/__tests__/RouterContainer.test.tsx +++ b/src/components/__tests__/RouterContainer.test.tsx @@ -9,12 +9,13 @@ const mockRouterValue = { currentPage: 'dashboard' as PageType, visiblePages: ['dashboard', 'timestamp'] as PageType[], pageOrder: ['timestamp'] as PageType[], - isLoaded: true, navigateTo: vi.fn(), syncNavigation: vi.fn(), goHome: vi.fn(), setVisiblePages: vi.fn(), setPageOrder: vi.fn(), + recentlyUsedTools: [] as PageType[], + isLoaded: true, }; vi.mock('@/providers/RouterProvider', () => ({ @@ -32,16 +33,7 @@ describe('RouterContainer 组件', () => { }; describe('渲染测试', () => { - it('isLoaded 为 false 时应渲染骨架屏', () => { - mockRouterValue.isLoaded = false; - const { container } = renderWithProvider(); - // 骨架屏使用 animate-pulse 类 - const skeletons = container.querySelectorAll('.animate-pulse'); - expect(skeletons.length).toBeGreaterThan(0); - }); - - it('isLoaded 为 true 时应渲染页面内容', () => { - mockRouterValue.isLoaded = true; + it('mount 后应直接渲染页面结构(不等待 storage 加载)', () => { mockRouterValue.currentPage = 'dashboard'; const { container } = renderWithProvider(); expect(container.querySelector('.page-transition-dashboard')).toBeInTheDocument(); @@ -77,8 +69,7 @@ describe('RouterContainer 组件', () => { }); describe('页面级错误隔离', () => { - it('PageErrorBoundary 应包裹在 Suspense 内层', () => { - mockRouterValue.isLoaded = true; + it('PageErrorBoundary 应包裹页面内容', () => { mockRouterValue.currentPage = 'dashboard'; const { container } = renderWithProvider();