fix(cloudflare): restore group detail pages for ids other than 1

Static export only generates /cloudflare/groups/1.html. Unknown ids fell
through to the dashboard index, bouncing the browser home and triggering
React hydration error #418. Serve the generated group shell and resolve
the real id from the pathname, matching the websites detail fallback.
This commit is contained in:
ryan
2026-09-17 22:00:12 +08:00
parent bbd7f72c2d
commit a2404a50ef
6 changed files with 108 additions and 25 deletions
@@ -13,8 +13,22 @@ import { CloudflareService, NodeService } from '@/lib/services/openflare';
import { NextIntlClientProvider } from 'next-intl';
import zhCN from '@/messages/zh-CN.json';
let mockGroupId = '7';
let mockParamId = '7';
vi.mock('next/link', () => ({
default: ({
children,
href,
}: {
children: React.ReactNode;
href: string;
}) => <a href={href}>{children}</a>,
}));
vi.mock('next/navigation', () => ({
useParams: () => ({ id: '7' }),
useParams: () => ({ id: mockParamId }),
usePathname: () => `/cloudflare/groups/${mockGroupId}`,
}));
vi.mock('@/lib/services/openflare', async (importOriginal) => {
@@ -55,6 +69,8 @@ function renderPage() {
describe('Cloudflare group detail refresh', () => {
beforeEach(() => {
mockGroupId = '7';
mockParamId = '7';
vi.mocked(CloudflareService.getGroup).mockReset();
vi.mocked(CloudflareService.listAvailableDomains).mockReset();
vi.mocked(NodeService.listNodes).mockReset();
@@ -94,6 +110,19 @@ describe('Cloudflare group detail refresh', () => {
});
});
it('uses the browser pathname ID when serving a static-export fallback shell', async () => {
mockParamId = '1';
renderPage();
await waitFor(() => {
expect(CloudflareService.getGroup).toHaveBeenCalledWith(7);
});
expect(CloudflareService.getGroup).not.toHaveBeenCalledWith(1);
expect(
await screen.findByRole('heading', { name: '生产节点' }),
).toBeVisible();
});
it('automatically refreshes detail data every five seconds', async () => {
vi.useFakeTimers({ shouldAdvanceTime: true });
renderPage();