From cc8561e1f43d2254439e90dc15098529f328f45b Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Mon, 9 Nov 2026 23:46:24 +0100 Subject: [PATCH] Uitloggen met uitgeschakeld CMS hing de app: de AppLayout-redirect naar /dashboard gold ook voor een gast (eindeloze navigatielus); alleen voor een ingelogde gebruiker Co-Authored-By: Claude Sonnet 5.5 --- frontend/src/components/layout/AppLayout.tsx | 6 +- .../auth/pages/LogoutWhileCmsOff.test.tsx | 57 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 frontend/src/features/auth/pages/LogoutWhileCmsOff.test.tsx diff --git a/frontend/src/components/layout/AppLayout.tsx b/frontend/src/components/layout/AppLayout.tsx index 74bea9a..93888f4 100644 --- a/frontend/src/components/layout/AppLayout.tsx +++ b/frontend/src/components/layout/AppLayout.tsx @@ -22,11 +22,15 @@ export function AppLayout() { }, [status, navigate]); useEffect(() => { + // Only for a signed-in user. A guest (just signed out) must be left alone: sending a guest to /dashboard + // makes the authenticated route redirect straight back to /login, and with the CMS switched off this + // effect then fires again - an endless navigation loop that froze the app after logout. + if (status !== 'authenticated') return; if (availability?.status === 'NotAvailable') { const allowed = ALLOWED_WHEN_UNAVAILABLE.some(p => location.pathname.startsWith(p)); if (!allowed) void navigate({ to: '/dashboard' }); } - }, [availability?.status, location.pathname, navigate]); + }, [status, availability?.status, location.pathname, navigate]); if (!isAuthenticated) { return null; diff --git a/frontend/src/features/auth/pages/LogoutWhileCmsOff.test.tsx b/frontend/src/features/auth/pages/LogoutWhileCmsOff.test.tsx new file mode 100644 index 0000000..77af49f --- /dev/null +++ b/frontend/src/features/auth/pages/LogoutWhileCmsOff.test.tsx @@ -0,0 +1,57 @@ +import { describe, expect, it, vi } from 'vitest'; +import { screen, waitFor } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import { http, HttpResponse } from 'msw'; +import { server } from '@/mocks/server'; +import { mockAuthenticated, renderApp } from '@/test/utils'; + +/** + * Field report (ASF test, reproducible on a phone): after signing out the admin hangs and later page loads start + * no API request at all. ASF is the site whose CMS had been switched off. This pins what the code does for a guest + * in exactly that situation: CMS 'not available', capabilities answering 503 to a guest (the gate), then logout. + */ +describe('signing out while the CMS is switched off', () => { + // Before the fix in AppLayout this test never finished: signing out sent the guest to /dashboard (CMS off, path not + // allowed), the authenticated route sent it back to /login, and the effect fired again - an endless navigation loop + // that froze the page (and, on a phone, ran into the browser's history-write limit, which throws in a loop). + function cmsOff() { + server.use( + http.get('*/Availability/status', () => + HttpResponse.json({ status: 'NotAvailable', message: 'Test', isMasterControlled: true }), + ), + http.get('*/System/capabilities', () => + HttpResponse.json({ title: 'Service Unavailable', status: 503 }, { status: 503 }), + ), + ); + } + + it('ends on the login page with the notice, without a render error or an endless request loop', async () => { + cmsOff(); + mockAuthenticated(); + const errors = vi.spyOn(console, 'error').mockImplementation(() => undefined); + const requests: string[] = []; + server.events.on('request:start', ({ request }) => { + requests.push(`${request.method} ${new URL(request.url).pathname}`); + }); + const user = userEvent.setup(); + renderApp('/dashboard'); + + await screen.findByTestId('user-menu-button'); + await user.click(screen.getByTestId('user-menu-button')); + await user.click(await screen.findByTestId('user-menu-logout')); + + expect(await screen.findByTestId('login-form-submit-button')).toBeInTheDocument(); + expect(await screen.findByTestId('login-cms-off')).toBeInTheDocument(); + + // settle: a loop would keep issuing requests / errors + const settled = requests.length; + await new Promise((r) => setTimeout(r, 600)); + server.events.removeAllListeners(); + + expect(requests.length).toBeLessThanOrEqual(settled + 2); + await waitFor(() => expect(screen.getByTestId('login-form-submit-button')).toBeInTheDocument()); + const renderErrors = errors.mock.calls.filter((c) => String(c[0]).includes('The above error') || String(c[0]).includes('Maximum update depth')); + expect(renderErrors).toHaveLength(0); + errors.mockRestore(); + }); +});