From 3908dc524af130f9fde63554e9c98d4913d764e5 Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Wed, 23 Sep 2026 11:40:56 -0400 Subject: [PATCH] Fix the shell: useState was used and never imported, so the app never mounted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The launch-screen work added a useState to App.jsx without adding it to the React import line, and the only symptom in production was a background: React threw while rendering the shell, so neither the app nor the splash ever mounted. "Uncaught ReferenceError: useState is not defined" at the top of the bundle is as fatal as a build error and much quieter — the page loads, the CSS applies, the aura paints, and nothing else happens. It shipped because no test rendered App. The whole point of a shell is that it can fail everything by failing once, so there is now a smoke test that mounts it against a mocked network: it checks the app renders at all, that the launch screen comes first with the photo and the mark on it, that the shell gets past it to a real screen, and that a signed-in device whose boot never finishes still gets its own data rather than being held on the splash. Checked against the bug itself — with useState removed from the import all three fail with that exact ReferenceError. Also swept every file in src/ for the same class of mistake (a hook called, its name not in the React import): App.jsx was the only one. --- frontend/src/App.jsx | 2 +- frontend/src/App.smoke.test.jsx | 65 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 frontend/src/App.smoke.test.jsx diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index f896f7b..98f10bd 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,4 +1,4 @@ -import { useEffect, useLayoutEffect, useRef } from 'react' +import { useEffect, useLayoutEffect, useRef, useState } from 'react' import { HashRouter, Routes, Route, Navigate, useNavigate, useLocation, useNavigationType } from 'react-router-dom' import { useStore } from './store/useStore.js' import { useUI } from './store/useUI.js' diff --git a/frontend/src/App.smoke.test.jsx b/frontend/src/App.smoke.test.jsx new file mode 100644 index 0000000..45ffc15 --- /dev/null +++ b/frontend/src/App.smoke.test.jsx @@ -0,0 +1,65 @@ +// @vitest-environment happy-dom +/* The app shell, rendered once, end to end. + * + * This exists because a missing hook import in App.jsx — `useState` used, never imported — shipped + * to production and the only symptom was a background: React threw while rendering the shell, so + * neither the app nor the launch screen ever mounted, and every test in the suite passed because + * none of them rendered App. A page that only ever needs to render is still a page worth rendering + * in a test: the whole class of "the bundle parses but the tree throws" lives here. */ +import React, { act } from 'react' +import { createRoot } from 'react-dom/client' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +// No network in a smoke test: the shell's boot() pulls config and state, and every one of those +// goes through lib/api.js. Everything else in that module stays real (Login reads IS_APPLE, BIO, +// passkeyLogin… from it), which is what `importOriginal` is for — a hand-listed mock would leave +// the screens importing exports that do not exist, and the error boundary would hide it. +vi.mock('./lib/api.js', async importOriginal => ({ + ...(await importOriginal()), + api: vi.fn(async () => ({})) +})) +vi.mock('./lib/back.js', () => ({ initBackButton: async () => () => {} })) +vi.mock('./lib/push.js', () => ({ syncPushSubscription: async () => {} })) + +const { default: App } = await import('./App.jsx') + +let host, root +beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true + localStorage.clear() + host = document.createElement('div') + document.body.appendChild(host) + root = createRoot(host) +}) +afterEach(() => { act(() => root.unmount()); host.remove() }) + +describe('the app shell', () => { + it('mounts without throwing, and shows the launch screen first', async () => { + await act(async () => { root.render() }) + // The splash: the shell renders it before anything else, which is what a launch screen is. + expect(host.querySelector('.boot-splash')).toBeTruthy() + expect(host.querySelector('img.boot-photo')?.getAttribute('src')).toBe('splash.webp') + expect(host.querySelector('img.boot-logo')?.getAttribute('src')).toBe('logo.png') + }) + + it('gets past the launch screen and paints a screen', async () => { + await act(async () => { root.render() }) + // Wait out the 500ms floor, then let boot() settle. + await act(async () => { await new Promise(r => setTimeout(r, 600)) }) + expect(host.querySelector('.boot-splash')).toBeNull() + // Something real is on screen — the login door for a device with no profile. The assertion is + // deliberately loose: the point is that the tree rendered, not which screen it chose. + expect(host.textContent.trim().length).toBeGreaterThan(0) + }) + + it('keeps local data visible when boot is slow, instead of holding the splash', async () => { + // A signed-in device whose boot never finishes (bad network): the splash covers the first half + // second and then gets out of the way, because the local copy is the whole point of offline. + localStorage.setItem('gym_user', JSON.stringify({ id: 'u1', name: 'Test' })) + const api = (await import('./lib/api.js')).api + api.mockImplementation(() => new Promise(() => {})) // never resolves + await act(async () => { root.render() }) + await act(async () => { await new Promise(r => setTimeout(r, 600)) }) + expect(host.querySelector('.boot-splash')).toBeNull() + }) +})