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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ jobs:
app/tests/artifacts-kit.test.ts
app/tests/artifacts-screens.test.tsx
app/tests/board-row-layout.test.tsx
app/tests/boot-screen.test.ts
app/tests/bot-file-links-browser.test.tsx
app/tests/bot-long-instructions-layout.test.tsx
app/tests/bot-owner-lists-layout.test.tsx
Expand Down
223 changes: 223 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,232 @@
}
} catch {}
</script>
<!--
THE SCREEN BEFORE THE APP ARRIVES, AND WHEN IT DOESN'T.

Until the app's own code and styles have loaded there is nothing else to draw, and a page with
nothing in it is plain white in a browser and in a phone's Home Screen app, dark theme or not.
On a weak connection, or when the app's code didn't download, it stayed white for good, with
nothing to press (OpenBot Cloud, 3 Dec 2026, on a conference's Wi-Fi). So, as Gmail does:

- the page's ground in the person's theme at once, and "Loading…" after a second;
- "OpenBot couldn't load" with Try again when the app's code or styles failed to download, or
when the app hasn't started 10 seconds in. It goes the moment the app draws, however late;
- gone the moment the app draws anything into #root, unless the app's styles never arrived:
the app without them is no better than this screen.

Plain CSS and a classic script, here in the page: nothing of the app's is there yet. The colors
are the scheme's tokens (tokens/src/scheme.ts), read from the app's stylesheet once it has
loaded, a skin's included, and the scheme's own values until then. The layout is the app's
error screen's (components/layout/route-error.tsx). app/tests/boot-screen.test.ts holds them.
Second, after the theme's script: tests read that one as the page's first.
-->
<style>
#openbot-boot {
position: fixed;
inset: 0;
z-index: 2147483647;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 1rem;
background: var(--background, oklch(0.983 0.003 247.9));
color: var(--foreground, oklch(0.108 0.042 264.7));
font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);
font-size: 1rem;
line-height: 1.5rem;
text-align: center;
-webkit-font-smoothing: antialiased;
}
.dark #openbot-boot {
background: var(--background, oklch(0.182 0.017 252));
color: var(--foreground, oklch(0.956 0.004 252));
}
/* Opened by OpenBot Desktop's setup, which faded out to the sidebar's ground (styles.css). */
html[data-from-setup] #openbot-boot {
background: var(--sidebar, oklch(0.948 0.01 251.8));
}
html[data-from-setup].dark #openbot-boot {
background: var(--sidebar, oklch(0.156 0.017 252));
}
#openbot-boot [data-boot-loading] {
margin: 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--muted-foreground, oklch(0.506 0.045 257.4));
}
.dark #openbot-boot [data-boot-loading] {
color: var(--muted-foreground, oklch(0.69 0.016 252));
}
#openbot-boot [data-boot-failed] {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
max-width: 20.5rem;
margin-top: -3rem;
padding: 1rem;
box-sizing: border-box;
}
#openbot-boot[data-state="waiting"] [data-boot-loading] {
visibility: hidden;
}
#openbot-boot[data-state="failed"] [data-boot-loading],
#openbot-boot:not([data-state="failed"]) [data-boot-failed] {
display: none;
}
#openbot-boot h1 {
margin: 0;
font-size: 1.5rem;
line-height: 2rem;
font-weight: 500;
letter-spacing: -0.025em;
text-wrap: balance;
}
#openbot-boot [data-boot-failed] p {
margin: 0.75rem 0 0;
font-size: 0.875rem;
line-height: 1.25rem;
color: var(--muted-foreground, oklch(0.506 0.045 257.4));
text-wrap: balance;
}
.dark #openbot-boot [data-boot-failed] p {
color: var(--muted-foreground, oklch(0.69 0.016 252));
}
#openbot-boot button {
box-sizing: border-box;
width: 100%;
height: 2.5rem;
margin-top: 2rem;
padding: 0 0.625rem;
border: 1px solid transparent;
border-radius: var(--radius-md, 0.5rem);
background: var(--primary, oklch(0.108 0.042 264.7));
color: var(--primary-foreground, oklch(1 0 0));
font: inherit;
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 500;
letter-spacing: -0.025em;
cursor: pointer;
outline: none;
transition: background-color 150ms cubic-bezier(0.23, 1, 0.32, 1);
}
.dark #openbot-boot button {
background: var(--primary, oklch(0.956 0.004 252));
color: var(--primary-foreground, oklch(0.108 0.017 252));
}
#openbot-boot button:hover {
background: color-mix(in oklch, var(--primary, oklch(0.108 0.042 264.7)) 80%, transparent);
}
.dark #openbot-boot button:hover {
background: color-mix(in oklch, var(--primary, oklch(0.956 0.004 252)) 80%, transparent);
}
#openbot-boot button:focus-visible {
border-color: var(--ring, oklch(0.638 0.167 276.1));
box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring, oklch(0.638 0.167 276.1)) 50%, transparent);
}
.dark #openbot-boot button:focus-visible {
border-color: var(--ring, oklch(0.713 0.151 277.7));
box-shadow: 0 0 0 3px color-mix(in oklch, var(--ring, oklch(0.713 0.151 277.7)) 50%, transparent);
}
</style>
<script>
(() => {
// "Loading…" after a second, and "OpenBot couldn't load" once the app hasn't started in ten.
const LOADING_AFTER_MS = 1000;
const FAILED_AFTER_MS = 10000;
let waited = 0;
let failed = false;
let stylesFailed = false;
let up = false;
// The stylesheets and scripts the page itself names, read once it has been parsed.
let named = null;

function draw() {
const screen = document.getElementById("openbot-boot");
if (!screen) return;
const root = document.getElementById("root");
if (!up && root && root.firstChild) up = true;
if (up && !stylesFailed) {
screen.remove();
return;
}
screen.dataset.state =
failed || stylesFailed || waited >= FAILED_AFTER_MS
? "failed"
: waited >= LOADING_AFTER_MS
? "loading"
: "waiting";
}

// A file of the app that didn't download: its code, a file its code needs at once, or its
// styles. An error of the page's own scripts once they run is not this screen's: the app is
// drawing then, and its error screens say what failed.
window.addEventListener(
"error",
(event) => {
const element = event.target;
if (!element?.tagName) return;
const tag = element.tagName.toLowerCase();
const rel = (element.getAttribute("rel") || "").toLowerCase().split(/\s+/);
const styles = tag === "link" && rel.includes("stylesheet");
const code =
(tag === "script" && element.type === "module") ||
(tag === "link" && rel.includes("modulepreload"));
if (!styles && !code) return;
// Once the app is up, only the page's own stylesheet counts: a part of the app it loads
// later has its own recovery (lib/chunk-recovery.ts).
if (up && !(styles && named?.includes(element))) return;
if (styles) stylesFailed = true;
failed = true;
draw();
},
true,
);

document.addEventListener("click", (event) => {
const target = event.target;
if (target?.closest?.("[data-boot-retry]")) window.location.reload();
});

function watch() {
named = [
...document.querySelectorAll(
'link[rel~="stylesheet"], link[rel~="modulepreload"], script[src]',
),
];
const root = document.getElementById("root");
if (root && typeof MutationObserver === "function")
new MutationObserver(draw).observe(root, { childList: true });
draw();
}
if (document.readyState === "loading")
document.addEventListener("DOMContentLoaded", watch);
else watch();

setTimeout(() => {
waited = LOADING_AFTER_MS;
draw();
}, LOADING_AFTER_MS);
setTimeout(() => {
waited = FAILED_AFTER_MS;
draw();
}, FAILED_AFTER_MS);
})();
</script>
</head>
<body>
<div id="root"></div>
<div id="openbot-boot" data-state="waiting">
<p data-boot-loading role="status">Loading…</p>
<div data-boot-failed role="alert">
<h1>OpenBot couldn't load</h1>
<p>Check your connection.</p>
<button data-boot-retry type="button">Try again</button>
</div>
</div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
13 changes: 13 additions & 0 deletions app/tests/boot-screen.fixture.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createRoot } from "react-dom/client";

/**
* The app as `boot-screen.test.ts` serves it: React drawing into `#root`, as `main.tsx` does, and
* nothing else. What the screen before the app reacts to is the first thing drawn there.
*/
const root = document.getElementById("root");
if (root)
createRoot(root).render(
<main data-app="" style={{ padding: "2rem" }}>
OpenBot is up
</main>,
);
Loading
Loading