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 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 23:46:24 +01:00
co-authored by Claude Sonnet 5.5
parent 893c40c46d
commit cc8561e1f4
2 changed files with 62 additions and 1 deletions
+5 -1
View File
@@ -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;
@@ -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();
});
});