Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

A screen that fails to draw no longer blanks the whole app

Yashwanth Kamireddic364c6277bce
diff --git a/.uiverify/boundary.mjs b/.uiverify/boundary.mjs
new file mode 100644
index 0000000..b5e8010
--- /dev/null
+++ b/.uiverify/boundary.mjs
@@ -0,0 +1,44 @@
+// One screen failing to draw must not take the app with it.
+//
+// Replaying the real library, a contact row that threw while drawing its photo unmounted
+// everything: the sidebar, every screen, the way back — a blank window until a restart.
+import { engine } from "./engine.mjs";
+import { SERVICES, installStub } from "./stub.mjs";
+
+const b = await engine.launch();
+const ctx = await b.newContext({ viewport: { width: 1280, height: 820 } });
+await ctx.addInitScript(installStub, { screen: "library", services: SERVICES, twoFactor: null,
+ calendarFixture: true, notesFixture: true, contactsFixture: true, driveFixture: true, remindersFixture: true });
+// A row that throws while it draws: a contact with a photo, whose address cannot be made.
+await ctx.addInitScript(() => {
+ const internals = window.__TAURI_INTERNALS__;
+ const invoke = internals.invoke;
+ internals.convertFileSrc = () => { throw new Error("cannot make a photo address"); };
+ internals.invoke = async (cmd, args) => {
+ const answer = await invoke(cmd, args);
+ if (cmd === "contacts_list" && Array.isArray(answer) && answer[0]) answer[0] = { ...answer[0], photoUrl: "x" };
+ return answer;
+ };
+});
+const page = await ctx.newPage();
+page.on("pageerror", () => {});
+await page.goto("http://localhost:4173", { waitUntil: "networkidle" });
+
+let failures = 0;
+const ok = (pass, yes, no) => { console.log(pass ? `PASS ${yes}` : `FAIL ${no}`); if (!pass) failures++; };
+
+await page.locator(".nav-item", { hasText: "Contacts" }).click();
+await page.waitForTimeout(500);
+const after = await page.evaluate(() => ({
+ sidebar: document.querySelectorAll(".nav-item").length,
+ said: document.querySelector(".screen-failed")?.textContent ?? null,
+}));
+ok(after.sidebar === 5, "a screen that fails to draw leaves the sidebar", `the app went blank: ${JSON.stringify(after)}`);
+ok(Boolean(after.said?.includes("Contacts couldn’t be shown")), "and says so in its place", `nothing said: ${JSON.stringify(after)}`);
+if (after.sidebar === 5) {
+ await page.locator(".nav-item", { hasText: "Notes" }).click();
+ await page.waitForTimeout(400);
+ ok((await page.locator(".note-row").count()) > 0, "and every other screen still opens", "Notes did not open after");
+}
+await b.close();
+process.exitCode = failures === 0 ? 0 : 1;
diff --git a/check.sh b/check.sh
index 810645f..ad5683b 100755
--- a/check.sh
+++ b/check.sh
@@ -42,6 +42,7 @@ step "uploading" node .uiverify/drive-upload.mjs
step "calendar grids" node .uiverify/calendar.mjs
step "every size" node .uiverify/sizes.mjs
step "narrow windows" node .uiverify/compact.mjs
+step "a screen failing" node .uiverify/boundary.mjs
# The same screens in WebKit, the engine Quince draws in. Chromium above catches most things;
# this catches what only WebKit does — pointer capture, blur on removal, its own layout.
@@ -54,6 +55,7 @@ step "webkit: drive" env ENGINE=webkit node .uiverify/drive-upload.mjs
step "webkit: calendar" env ENGINE=webkit node .uiverify/calendar.mjs
step "webkit: sizes" env ENGINE=webkit node .uiverify/sizes.mjs
step "webkit: narrow" env ENGINE=webkit node .uiverify/compact.mjs
+step "webkit: failing" env ENGINE=webkit node .uiverify/boundary.mjs
printf '\n'
if [ "$fail" -eq 0 ]; then printf '\033[32mAll checks passed.\033[0m\n'; else printf '\033[31mSome checks failed.\033[0m\n'; fi
diff --git a/src/components/ScreenBoundary.tsx b/src/components/ScreenBoundary.tsx
new file mode 100644
index 0000000..4577fcb
--- /dev/null
+++ b/src/components/ScreenBoundary.tsx
@@ -0,0 +1,33 @@
+import { Component, type ReactNode } from "react";
+
+/**
+ * Keeps a failure in one screen inside that screen.
+ *
+ * Without a boundary React unmounts everything on a render error, so one bad row anywhere
+ * took the sidebar, every screen and the way back with it: the window went blank and only a
+ * restart helped. Here the screen says what happened and can be opened again; the rest of
+ * the app, and everything stored, carry on.
+ */
+export class ScreenBoundary extends Component<{ children: ReactNode; name: string }, { failed: Error | null }> {
+ state = { failed: null as Error | null };
+
+ static getDerivedStateFromError(failed: Error) {
+ return { failed };
+ }
+
+ componentDidCatch(error: Error) {
+ console.error(`${this.props.name} failed to draw:`, error);
+ }
+
+ render() {
+ if (!this.state.failed) return this.props.children;
+ return (
+ <div className="screen-failed" role="alert">
+ <p>{this.props.name} couldn’t be shown. Nothing stored was affected.</p>
+ <button className="quiet" onClick={() => this.setState({ failed: null })}>
+ Open {this.props.name} Again
+ </button>
+ </div>
+ );
+ }
+}
diff --git a/src/screens/Library.tsx b/src/screens/Library.tsx
index 87385fd..243546c 100644
--- a/src/screens/Library.tsx
+++ b/src/screens/Library.tsx
@@ -9,6 +9,7 @@ import { RemindersView } from "./RemindersView";
import { NotesView } from "./NotesView";
import { ContactsView } from "./ContactsView";
import { DriveView } from "./DriveView";
+import { ScreenBoundary } from "../components/ScreenBoundary";
/**
* What the sidebar holds: the services with a real screen behind them, most used first.
@@ -153,16 +154,21 @@ export function Library({ onSignOut }: { onSignOut: () => void }) {
</nav>
<main className="content">
- {selected === "calendar" ? (
- <CalendarView />
- ) : selected === "reminders" ? (
- <RemindersView />
- ) : selected === "notes" ? (
- <NotesView />
- ) : selected === "contacts" ? (
- <ContactsView />
- ) : selected === "drivews" ? (
- <DriveView />
+ {selected && SCREENS.some((s) => s.key === selected) ? (
+ // Keyed by screen, so moving to another screen also clears a failed one.
+ <ScreenBoundary key={selected} name={SCREENS.find((s) => s.key === selected)?.name ?? "This screen"}>
+ {selected === "calendar" ? (
+ <CalendarView />
+ ) : selected === "reminders" ? (
+ <RemindersView />
+ ) : selected === "notes" ? (
+ <NotesView />
+ ) : selected === "contacts" ? (
+ <ContactsView />
+ ) : (
+ <DriveView />
+ )}
+ </ScreenBoundary>
) : (
ready &&
services.length === 0 && (
diff --git a/src/styles/app.css b/src/styles/app.css
index 29cbc5b..cdad919 100644
--- a/src/styles/app.css
+++ b/src/styles/app.css
@@ -1634,3 +1634,7 @@
}
.notice-close:hover { background: color-mix(in srgb, var(--text) 10%, transparent); color: var(--text); }
.notice-close:focus-visible { outline: 3px solid var(--gold-ring); }
+
+/* A screen that failed to draw, in place of the screen — the rest of the app carries on. */
+.screen-failed { max-width: 46ch; margin: 64px auto 0; text-align: center; color: var(--text-2); }
+.screen-failed p { margin: 0 0 12px; font-size: var(--t-13); }