Offer a retry after a failed attempt.

Offer a retry after a failed attempt with a small React component and explicit browser behavior.

JSX App.jsx
import { useState, useRef } from 'react';

export default function App() {
    const attempts = useRef(0);
    const [status, setStatus] = useState("Idle");
    async function load() { attempts.current++; try { if (attempts.current === 1) throw new Error("fixture failure"); await Promise.resolve(); setStatus("Loaded"); } catch { setStatus("Try again"); } }

    return (
        <main data-ready>
            <button onClick={load}>Load</button><output>{status}</output>
        </main>
    );
}

Expected output EXAMPLE

Click the button.
The output displays “Try again”.
Click the button.
The output displays “Loaded”.

Details

Use this App.jsx in a React 19 project with JSX support. Mount the default App component with createRoot in your existing entry point. The test mounts this exact component and checks its rendered behavior.

✓ Verified

Tested on Ubuntu 24.04.3 LTS · · Node.js v24.15.0; Chromium 141.0.7390.37 · esbuild 0.28.2; playwright 1.56.0; react 19.3.1; react-dom 19.3.1

Test inputs, results and environment

The exact published code ran in a dedicated Linux test container with prepared inputs. Dedicated test container, external networking disabled, read-only root, temporary per-example working directory. Browser network requests are blocked. Fixtures and output records are isolated from the application database. Testing covers this example and its stated checks, not every input, operating system, or runtime version. The Linux container shares its host's kernel; this is not a native Windows test.

Architecture / host kernel
x86_64 / 6.18.54.1-microsoft-standard-WSL2
Snippet identity / locale
uid=65534, gid=65534 (unprivileged) / C.UTF-8
Interpreter invocation
bundle the exact published component with esbuild; mount it in Chromium and execute browser assertions
Container image ID
sha256:c9bce90110f636fe04907469a37e9c8ac888171fd569cbf87101743ec7cdf099
Code SHA-256
606dbfd91d3a155eb03cdb40c17f4502d7b5e995dc09b9093baf5bc772ab3c8d
Dependencies
esbuild 0.28.2; playwright 1.56.0; react 19.3.1; react-dom 19.3.1

Test input setup

These are the prepared inputs used by the test harness. See Details above for the prerequisites and how to run this example.

The harness supplies index.html and mounts the published component with locally installed, pinned dependencies.

Observed standard output

Expected output describes the rendered page. The standard-output record below is the browser test harness receipt; the additional assertions check the result and interactions.

Offer a retry after a failed attempt: browser checks passed.

Exit code: 0. Standard error: empty. Validation: Shape/content assertions. System-dependent values above are one recorded run.

Additional assertions that passed

Checks recorded by the test harness. Where Python assertions are shown, browser cases use Playwright and simulator cases may inspect pin transitions: result.stdout is captured output, work is the temporary directory, and Path is pathlib.Path. The harness also imports json and csv.

await page.getByRole('button').click(); await text('output','Try again'); await page.getByRole('button').click(); await text('output','Loaded');