From d4e54f3f6ca0c8bf9eeebfcccb169b15f018fd24 Mon Sep 17 00:00:00 2001 From: Zakk Date: Mon, 28 Sep 2026 03:25:15 +1000 Subject: [PATCH] fix(login): keep the form when the showcase fails to load The showcase chunk loaded under Suspense with no error boundary, so a failed import blanked the whole sign-in page. LoadBoundary takes an optional fallback, and the login page gives it the same empty panel it shows while the chunk loads; the form beside it keeps working. --- e2e/chunks.spec.ts | 26 ++++++++++++++++++++++++++ src/shell/Login.tsx | 13 +++++++++---- src/ui/LoadBoundary.tsx | 7 +++++-- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/e2e/chunks.spec.ts b/e2e/chunks.spec.ts index fb1984fd..490f3da8 100644 --- a/e2e/chunks.spec.ts +++ b/e2e/chunks.spec.ts @@ -135,6 +135,32 @@ for (const chunk of ['Policies', 'AreaChart', 'Sparkline', 'Donut']) { }); } +test('a rejected showcase import leaves its panel empty and the sign-in form working', async ({browser}) => { + const context = await browser.newContext({serviceWorkers: 'block', viewport: {width: 1280, height: 800}}); + const page = await context.newPage(); + const uncaught: string[] = []; + page.on('pageerror', error => uncaught.push(error.message)); + await page.addInitScript(() => { + localStorage.setItem('doona-profiles', JSON.stringify([{id: 'demo', name: 'Demo', api: 'mock', token: ''}])); + localStorage.setItem('doona-profile', 'demo'); + localStorage.setItem('doona-lang', 'en'); + }); + const rejected = page.waitForRequest(/\/LoginShowcase-[^/]+\.js$/); + await page.route('**/assets/LoginShowcase-*.js', route => route.abort()); + try { + await page.goto('/#/activity'); + await rejected; + const login = page.locator('.rp-login-page'); + await expect(login.locator('.rp-login-showcase[aria-hidden="true"]')).toBeVisible(); + await expect(login.locator('.rp-alert')).toHaveCount(0); + await Promise.all([page.waitForEvent('load'), login.getByRole('button', {name: 'Sign in', exact: true}).click()]); + await expect(page.locator('.rp-nav[href="#/activity"]')).toHaveAttribute('aria-current', 'page'); + expect(uncaught).toEqual([]); + } finally { + await context.close(); + } +}); + test('the idle warm-up loads the search dialog before any interaction', async ({page}) => { const requested = page.waitForRequest(/\/SearchDialog-[^/]+\.js$/); await page.goto('/#/activity'); diff --git a/src/shell/Login.tsx b/src/shell/Login.tsx index 4d1e73b1..5c7a1e64 100644 --- a/src/shell/Login.tsx +++ b/src/shell/Login.tsx @@ -3,13 +3,16 @@ import {useT, type Lang} from '../i18n'; import {useLogin} from './useLogin'; import {Button, ErrorMessage, InlineAlert, Link, Loading, TextField} from '../ui/ui'; import {useMediaQuery} from '../ui/hooks'; +import {LoadBoundary} from '../ui/LoadBoundary'; import LinkOut from '../ui/icons/LinkOut'; import logo from '../logo.svg'; import {href} from './route'; import {LanguageMenu, SchemeToggle} from './AppearanceControls'; -// The panel beside the form loads only where it is shown, so the sign-in chunk stays the same size on a phone. +// The panel beside the form loads only where it is shown, so the sign-in chunk stays the same size on a phone. Until it +// arrives, or if it never does, the panel stays empty and the form works as before. const LoginShowcase = lazy(() => import('./LoginShowcase')); +const emptyShowcase = {wide && ( - + + + + + )} ); diff --git a/src/ui/LoadBoundary.tsx b/src/ui/LoadBoundary.tsx index 5338ed62..03f9ca99 100644 --- a/src/ui/LoadBoundary.tsx +++ b/src/ui/LoadBoundary.tsx @@ -1,7 +1,9 @@ import {Component, type ReactNode} from 'react'; import {ErrorMessage} from './Feedback'; -export class LoadBoundary extends Component<{children: ReactNode}, {error: Error | null}> { +// A lazy part that fails to load reports it with a retry. `fallback` stands in silently instead, for a part the page +// works without. +export class LoadBoundary extends Component<{children: ReactNode; fallback?: ReactNode}, {error: Error | null}> { override state: {error: Error | null} = {error: null}; static getDerivedStateFromError(error: unknown) { @@ -10,6 +12,7 @@ export class LoadBoundary extends Component<{children: ReactNode}, {error: Error override render() { // Reload clears both React.lazy's rejected promise and the browser's failed module entry. - return this.state.error ? location.reload()} /> : this.props.children; + if (!this.state.error) return this.props.children; + return this.props.fallback ?? location.reload()} />; } }