fix(web): bound lazy route recovery
This commit is contained in:
@@ -15,6 +15,7 @@ describe('route recovery boundary', () => {
|
||||
it('recognizes deployment-related lazy chunk failures', () => {
|
||||
expect(isRouteChunkError(new TypeError('Failed to fetch dynamically imported module: /assets/Monitor-old.js'))).toBe(true);
|
||||
expect(isRouteChunkError(new Error('Loading chunk 18 failed'))).toBe(true);
|
||||
expect(isRouteChunkError(Object.assign(new Error('Route chunk load timed out after 12000ms: history'), { name: 'RouteChunkLoadTimeoutError' }))).toBe(true);
|
||||
expect(isRouteChunkError(new Error('Cannot read properties of undefined'))).toBe(false);
|
||||
});
|
||||
|
||||
@@ -36,6 +37,20 @@ describe('route recovery boundary', () => {
|
||||
expect(screen.getByText(/旧标签页仍引用上一版本资源/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('explains a bounded route timeout instead of leaving the loading skeleton forever', () => {
|
||||
vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
window.sessionStorage.setItem('vehicle-platform:route-chunk-reload', JSON.stringify({ routeKey: '/history', at: Date.now() }));
|
||||
const TimeoutPage = () => {
|
||||
throw Object.assign(new Error('Route chunk load timed out after 10000ms: history'), { name: 'RouteChunkLoadTimeoutError' });
|
||||
};
|
||||
|
||||
render(<MemoryRouter future={ROUTER_FUTURE} initialEntries={['/history']}><RoutePage page={TimeoutPage} label="历史数据" /></MemoryRouter>);
|
||||
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('页面资源加载超时');
|
||||
expect(screen.getByText(/网络暂时不稳定/)).toBeInTheDocument();
|
||||
expect(screen.getByRole('button', { name: /刷新当前页面/ })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('keeps a meaningful content skeleton visible while a route chunk is pending', () => {
|
||||
const PendingPage = lazy(() => new Promise<never>(() => undefined));
|
||||
const { container } = render(<MemoryRouter future={ROUTER_FUTURE} initialEntries={['/access']}><RoutePage page={PendingPage} label="接入管理" /></MemoryRouter>);
|
||||
|
||||
Reference in New Issue
Block a user