Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Common issues and how to resolve them.

**Prevention**: Bookmark `/fix-cache.html` or use the link in Settings → Fix app. Since v2.813 the app also updates itself properly: the app reloads itself onto a new deploy at a quiet moment (first paint before any touch, a route change — a new page or a new `?tab=` (v2.4214) — with nothing open, idle — hidden 5 min or untouched 30 min — with nothing unsaved and no write in flight, never over words someone typed and has not sent (v2.8499, `pageHoldsTypedText`), and looked at a second time when the reload would fire, where a write is waited out and a touch, typed words or anything open hands it to the pill (v2.7600): [src/lib/autoReload.ts](../src/lib/autoReload.ts), [src/lib/unsavedWork.ts](../src/lib/unsavedWork.ts); inline editors keep a per-tab draft that comes back after the reload, [src/lib/reloadDraft.ts](../src/lib/reloadDraft.ts); v2.3740–v2.3742) and otherwise shows the "A new version is ready" pill (prompt-mode service worker, [src/components/UpdatePrompt.tsx](../src/components/UpdatePrompt.tsx)), whose **Reload** over typed words reloads nothing at first: the page is walked through each place that holds them, ringed for a second, and the press becomes **Reload anyway** (v2.8499, `src/lib/typedTextTour.ts`, `src/lib/updatePillWarn.ts`); the gear menu's **Hard Reload** and **Reload** on a page that could not load ask the same way through one bar (v2.8513, `src/lib/reloadOverWords.ts`, `src/components/ReloadOverWordsBar.tsx`) and long-lived tabs check for updates hourly and on tab re-focus — stale builds, the raw material for these white screens, should now be rare.

**Slow for one person, not stuck (v2.9273)**: do not send them to Fix app, which clears the cached files and measures nothing. Have them press **Check my connection** in the Fix app box at Settings → Advanced (`ConnectionCheckCard.tsx`, kernel `src/lib/connectionCheck.ts`) and paste **Copy the report** back. It times the site, the API's health address, their own `users` row and the Bids list read, three tries each, and its top sentence says whether the slow part is their connection or the app's own reads. Nothing is kept or sent. Helpers and subcontractors do not have Advanced.

---

## Supabase database unresponsive / high disk I/O
Expand Down
28 changes: 28 additions & 0 deletions docs/recent-features/v2.9273.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# v2.9273 — Settings: check your connection when the app is slow (2026-12-03)

A teammate reported the live app as nearly too slow to use, worst on the Bid Board, and the report came with no numbers. The Fix app page measured nothing: it is a static page that clears the cached files. The owner asked for a tool a person can run to measure their own connection. Client only. No migration, no function change, nothing kept, nothing owed on prod.

## What changed

- **Check my connection**, in the *Fix app* box at Settings → Advanced ([`ConnectionCheckCard.tsx`](../../src/components/settings/ConnectionCheckCard.tsx)). One press times four things, three tries each, one after another, no try waiting past 10 seconds:
- the site: one small file with an address no cache has seen;
- the API: the auth health address, which reads no table;
- a small read: the person's own `users` row;
- the Bid Board's read: the Bids page's own list read, its rows thrown away. A role that cannot open Bids (`canOpenBids`) is not shown this line.
- **The words** are the kernel [`connectionCheck.ts`](../../src/lib/connectionCheck.ts): a line's time is the middle of its tries (`summarizeTries`), under 1 s reads *fast*, 1 to 3 s *slow*, over 3 s *very slow*, none in 10 s *did not answer* (`speedOf`). One sentence on top (`checkVerdict`) names the person's connection when the site or the API is slow, the app's own reads when both are fast and a read is slow, and says so when everything was fast.
- **Copy the report** puts plain lines on the clipboard (`reportText`): the verdict, the lines, the build, the role, the connection kind where the browser gives one, the hour with its zone and the browser's own name. No name, email, job or figure. Where the clipboard is refused the lines are shown in a box to copy by hand.
- **The timings** are [`connectionCheckIo.ts`](../../src/lib/connectionCheckIo.ts) (`timeTry`, `runConnectionCheck`). They only read.
- The Bids list select moved from `useBidsPageData.ts` to [`lib/bids/bidListSelect.ts`](../../src/lib/bids/bidListSelect.ts), so the check times the very read the board sends and a lower layer reads nothing from a hook.
- The static Fix page (`public/fix-cache.html`) gained one line that points a slow, not stuck, person to the press. Settings search finds *Check my connection*, and `#settings-connection-check` opens the folded Advanced group.

## Who can press it

Every role that has Settings → Advanced. Helpers and subcontractors do not (the gate in `Settings.tsx` is unchanged).

## Guides

*know what to do when the app is slow* has a new section, **Check your connection**. *fix the app when it won't load* links to it.

## Tests

`src/lib/connectionCheck.test.ts` (the speeds, the middle try, the verdict, the report), `src/components/settings/ConnectionCheckCard.render.test.tsx` (the press, the lines, the copy).
1 change: 1 addition & 0 deletions public/fix-cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h1>Fix PipeTooling</h1>
<p>If the app shows a white screen after an update, this will clear cached files and reset storage so the app can load correctly.</p>
<button id="fix" type="button">Fix app</button>
<div id="status"></div>
<p style="margin-top: 1.5rem;">Is the app slow, not stuck? Sign in, open Settings, then Advanced, and press <strong>Check my connection</strong>. It times the app from your device.</p>

<script>
document.getElementById('fix').onclick = async function () {
Expand Down
85 changes: 85 additions & 0 deletions src/components/settings/ConnectionCheckCard.render.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// @vitest-environment jsdom
/**
* Settings → Advanced → Fix app: **Check my connection** (v2.9273). The press runs the check, the lines and the
* verdict draw, and **Copy the report** puts plain lines with no person in them on the clipboard.
*/
import { afterEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, screen, waitFor } from '@testing-library/react'
import type { CheckLine } from '../../lib/connectionCheck'
import type { ConnectionCheckArgs } from '../../lib/connectionCheckIo'

const { run } = vi.hoisted(() => ({ run: vi.fn() }))

vi.mock('../../lib/supabase', async () => {
const { makeSupabaseStub } = await import('../../test/renderSmokeMocks')
return { supabase: makeSupabaseStub() }
})
vi.mock('../../lib/connectionCheckIo', () => ({
runConnectionCheck: (args: ConnectionCheckArgs) => run(args),
checkFactsNow: (role: string | null) => ({ browser: 'Sample Browser', build: 'v2.9273', connection: null, when: 'Thu, Dec 3, 9:14 AM CST', role }),
}))

import ConnectionCheckCard from './ConnectionCheckCard'
import { renderWithProviders } from '../../test/renderSmokeMocks'

const FAST: CheckLine[] = [
{ key: 'site', tries: [300, 250, 400] },
{ key: 'api', tries: [200, 220, 300] },
{ key: 'smallRead', tries: [400, 380, 600] },
]
const SLOW_BOARD: CheckLine = { key: 'bidBoard', tries: [4200, 3900, 5100] }

describe('ConnectionCheckCard', () => {
afterEach(() => {
cleanup()
run.mockReset()
})

it('times the four lines for a role that opens Bids, and names the app when the board is slow', async () => {
run.mockImplementation(async (args: ConnectionCheckArgs) => {
args.onStart?.('site', ['site', 'api', 'smallRead', 'bidBoard'])
return [...FAST, SLOW_BOARD]
})
renderWithProviders(<ConnectionCheckCard userId="u-1" role="estimator" />)
fireEvent.click(screen.getByRole('button', { name: 'Check my connection' }))
await waitFor(() => expect(screen.getByText("Your connection is fine. The app's own reads are slow. Send this report to the office.")).toBeTruthy())
expect(run.mock.calls[0]![0]).toMatchObject({ userId: 'u-1', withBidBoard: true })
expect(screen.getByText("The Bid Board's read")).toBeTruthy()
expect(screen.getByText('4.2 s')).toBeTruthy()
expect(screen.getByRole('button', { name: 'Check again' })).toBeTruthy()
})

it('copies plain lines with no person in them', async () => {
const writeText = vi.fn().mockResolvedValue(undefined)
Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true })
run.mockResolvedValue(FAST)
renderWithProviders(<ConnectionCheckCard userId="u-1" role={null} />)
fireEvent.click(screen.getByRole('button', { name: 'Check my connection' }))
await waitFor(() => expect(screen.getByText('Everything answered fast from here.')).toBeTruthy())
expect(run.mock.calls[0]![0]).toMatchObject({ withBidBoard: false })
expect(screen.queryByText("The Bid Board's read")).toBeNull()
fireEvent.click(screen.getByRole('button', { name: 'Copy the report' }))
await waitFor(() => expect(screen.getByText('Copied. Paste it in a message to the office.')).toBeTruthy())
const text = writeText.mock.calls[0]![0] as string
expect(text.split('\n')[0]).toBe('PipeTooling connection check')
expect(text).toContain('The site: 0.3 s · fast · slowest try 0.4 s')
expect(text).toContain('Build: v2.9273')
expect(text).not.toContain('u-1')
})

it('shows the lines to copy by hand where the clipboard is refused', async () => {
Object.defineProperty(navigator, 'clipboard', { value: { writeText: vi.fn().mockRejectedValue(new Error('refused')) }, configurable: true })
run.mockResolvedValue(FAST)
renderWithProviders(<ConnectionCheckCard userId="u-1" role="estimator" />)
fireEvent.click(screen.getByRole('button', { name: 'Check my connection' }))
await waitFor(() => expect(screen.getByRole('button', { name: 'Copy the report' })).toBeTruthy())
fireEvent.click(screen.getByRole('button', { name: 'Copy the report' }))
await waitFor(() => expect(screen.getByText('Could not copy. Select the lines below and copy them by hand.')).toBeTruthy())
expect((screen.getByLabelText('The report') as HTMLTextAreaElement).value).toContain('Everything answered fast from here.')
})

it('is a dead press until the person is known', () => {
renderWithProviders(<ConnectionCheckCard userId={null} role={null} />)
expect((screen.getByRole('button', { name: 'Check my connection' }) as HTMLButtonElement).disabled).toBe(true)
})
})
193 changes: 193 additions & 0 deletions src/components/settings/ConnectionCheckCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
/**
* Settings → Advanced → Fix app: **Check my connection** (v2.9273).
*
* One press times the site, the API, a small read and the Bid Board's read from the person's own browser, three tries
* each, and says in one sentence whether the slow part is their connection or the app's own reads. **Copy the report**
* puts the plain lines on the clipboard. Nothing is kept and nothing is sent. The words and the sums are
* `lib/connectionCheck.ts`; the timings are `lib/connectionCheckIo.ts`.
*/
import { useEffect, useRef, useState } from 'react'
import { canOpenBids } from '../../lib/bids/bidsTabAccess'
import {
CHECK_AGAIN_LABEL,
CHECK_COPIED_WORDS,
CHECK_COPY_FAILED_WORDS,
CHECK_COPY_LABEL,
CHECK_LEAD_WORDS,
CHECK_LINE_HINTS,
CHECK_LINE_LABELS,
CHECK_PRESS_LABEL,
CHECK_SPEED_WORDS,
CHECK_TRIES,
checkVerdict,
factLines,
lineSlowestWords,
lineSpeed,
lineTimeWords,
progressWords,
reportText,
type CheckFacts,
type CheckLine,
} from '../../lib/connectionCheck'
import { checkFactsNow, runConnectionCheck } from '../../lib/connectionCheckIo'
import { DEAD_PRESS_FILL, DEAD_PRESS_TEXT } from '../../lib/deadPress'
import { ValueLine, ValueLines, WorkedOutValue } from '../valuesInPlace/ValuesInPlace'

type Copied = 'no' | 'yes' | 'failed'

export default function ConnectionCheckCard({ userId, role }: { userId: string | null; role: string | null }) {
const [running, setRunning] = useState<string | null>(null)
const [lines, setLines] = useState<ReadonlyArray<CheckLine>>([])
const [facts, setFacts] = useState<CheckFacts | null>(null)
const [copied, setCopied] = useState<Copied>('no')
const alive = useRef(true)
useEffect(() => {
alive.current = true
return () => {
alive.current = false
}
}, [])

const withBidBoard = canOpenBids(role as Parameters<typeof canOpenBids>[0])
const dead = !userId || running != null

async function run() {
if (!userId || running != null) return
setCopied('no')
setLines([])
setFacts(null)
setRunning('Checking…')
const done = await runConnectionCheck({
userId,
withBidBoard,
onStart: (key, keys) => {
if (alive.current) setRunning(progressWords(key, keys))
},
onLine: (soFar) => {
if (alive.current) setLines(soFar)
},
alive: () => alive.current,
})
if (!alive.current) return
setLines(done)
setFacts(checkFactsNow(role))
setRunning(null)
}

async function copy() {
if (!facts) return
try {
await navigator.clipboard.writeText(reportText(lines, facts))
setCopied('yes')
} catch {
setCopied('failed')
}
}

const finished = facts != null && running == null
const verdict = finished ? checkVerdict(lines) : null

return (
<div id="settings-connection-check" style={{ marginTop: '1rem', paddingTop: '1rem', borderTop: '1px solid var(--border)' }}>
<p style={{ margin: '0 0 0.75rem 0', fontSize: '0.875rem', color: 'var(--text-muted)' }}>{CHECK_LEAD_WORDS}</p>
<button
type="button"
onClick={() => void run()}
disabled={dead}
style={{
minHeight: 44,
padding: '0.5rem 1rem',
border: 'none',
borderRadius: 6,
fontFamily: 'inherit',
fontSize: '0.9375rem',
fontWeight: 600,
cursor: dead ? 'default' : 'pointer',
background: dead ? DEAD_PRESS_FILL : '#2563eb',
color: dead ? DEAD_PRESS_TEXT : '#fff',
}}
>
{finished ? CHECK_AGAIN_LABEL : CHECK_PRESS_LABEL}
</button>
<p role="status" aria-live="polite" style={{ margin: '0.75rem 0 0 0', fontSize: '0.875rem', color: 'var(--text-muted)', minHeight: running ? undefined : 0 }}>
{running}
</p>

{verdict && (
<p data-check-verdict={verdict.kind} style={{ margin: '0.25rem 0 0.75rem 0', fontSize: '1rem', fontWeight: 600 }}>
{verdict.words}
</p>
)}

{lines.length > 0 && (
<ValueLines>
{lines.map((line) => {
const speed = lineSpeed(line)
return (
<ValueLine key={line.key} label={<span title={CHECK_LINE_HINTS[line.key]}>{CHECK_LINE_LABELS[line.key]}</span>}>
<WorkedOutValue tone={speed === 'fast' ? 'green' : 'red'}>{lineTimeWords(line)}</WorkedOutValue>
{speed !== 'none' && (
<span style={{ color: 'var(--text-muted)' }}>
{' '}
· {CHECK_SPEED_WORDS[speed]} · {lineSlowestWords(line)}
</span>
)}
</ValueLine>
)
})}
</ValueLines>
)}

{finished && facts && (
<>
<p style={{ margin: '0.5rem 0', fontSize: '0.8125rem', color: 'var(--text-muted)' }}>Each line is the middle of {CHECK_TRIES} tries.</p>
<ValueLines>
{factLines(facts).map((f) => (
<ValueLine key={f.label} label={f.label}>
<WorkedOutValue>{f.value}</WorkedOutValue>
</ValueLine>
))}
</ValueLines>
<button
type="button"
onClick={() => void copy()}
style={{
marginTop: '0.75rem',
minHeight: 44,
padding: '0.5rem 1rem',
border: '1px solid var(--border)',
borderRadius: 6,
fontFamily: 'inherit',
fontSize: '0.9375rem',
fontWeight: 600,
cursor: 'pointer',
background: 'var(--surface)',
color: 'var(--text)',
}}
>
{CHECK_COPY_LABEL}
</button>
{copied === 'yes' && (
<p role="status" style={{ margin: '0.5rem 0 0 0', fontSize: '0.875rem', color: 'var(--text-green-700)' }}>
{CHECK_COPIED_WORDS}
</p>
)}
{copied === 'failed' && (
<>
<p role="status" style={{ margin: '0.5rem 0', fontSize: '0.875rem', color: 'var(--text-muted)' }}>
{CHECK_COPY_FAILED_WORDS}
</p>
<textarea
readOnly
aria-label="The report"
value={reportText(lines, facts)}
rows={12}
style={{ width: '100%', boxSizing: 'border-box', fontFamily: 'inherit', fontSize: '0.8125rem', color: 'var(--text)', background: 'var(--surface)', border: '1px solid var(--border)', borderRadius: 6, padding: '0.5rem' }}
/>
</>
)}
</>
)}
</div>
)
}
16 changes: 12 additions & 4 deletions src/components/settings/SettingsAdvancedTab.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Settings → Advanced tab: collapsible "Fix app" help + admin claim-code form
/** Settings → Advanced tab: collapsible "Fix app" help with **Check my connection** (v2.9273) + admin claim-code form
* + dev-only email-monitoring links (v2.2497) + a dev's Global Reload (v2.8527).
* Self-contained (v2.856): owns its section-open + claim-code state and the
* claim-dev edge-fn call; on success it invokes onRoleMaybeChanged so the parent
Expand All @@ -9,6 +9,7 @@ import { useEffect, useState } from 'react'
import type { FormEvent } from 'react'
import { FunctionsHttpError } from '@supabase/supabase-js'
import { supabase } from '../../lib/supabase'
import ConnectionCheckCard from './ConnectionCheckCard'
import GlobalReloadSettingsCard from './GlobalReloadSettingsCard'

/**
Expand All @@ -25,18 +26,24 @@ export default function SettingsAdvancedTab({
active,
isDev,
onRoleMaybeChanged,
userId = null,
role = null,
}: {
active: boolean
isDev: boolean
onRoleMaybeChanged: () => void
/** The signed-in person and their role, for **Check my connection** (v2.9273): its small read is their own row. */
userId?: string | null
role?: string | null
}) {
const [advancedSectionOpen, setAdvancedSectionOpen] = useState(false)
// `#settings-claim-code` (Needs You "Someone tried to become a dev", Tier-2 #17) and
// `#settings-global-reload` (the dev doors list): both sit inside this collapsed group, so the deep link opens it.
// `#settings-claim-code` (Needs You "Someone tried to become a dev", Tier-2 #17), `#settings-global-reload` (the dev
// doors list) and `#settings-connection-check` (the guide's link): each sits inside this collapsed group, so the
// deep link opens it.
useEffect(() => {
if (!active) return
const hash = typeof window !== 'undefined' ? window.location.hash : ''
if (hash === '#settings-claim-code' || hash === '#settings-global-reload') setAdvancedSectionOpen(true)
if (hash === '#settings-claim-code' || hash === '#settings-global-reload' || hash === '#settings-connection-check') setAdvancedSectionOpen(true)
}, [active])
const [code, setCode] = useState('')
const [codeError, setCodeError] = useState<string | null>(null)
Expand Down Expand Up @@ -110,6 +117,7 @@ export default function SettingsAdvancedTab({
</a>{' '}
to clear cached files and reload. Bookmark this link to use when the app won&apos;t load.
</p>
<ConnectionCheckCard userId={userId} role={role} />
</div>
{isDev && <GlobalReloadSettingsCard />}
{isDev && (
Expand Down
Loading
Loading