GeezerVison is showing github.com — fix(mobile): crash screen error preview keeps emoji whole at the 300-… · patroza/t3code@5db3ecd
File tree
Expand file treeCollapse file tree
Open diff view settings
apps/mobile/src/components
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { expect, it } from "vite-plus/test"; |
| 2 | + |
| 3 | +import { errorDetailsPreview } from "./RenderErrorBoundary.logic"; |
| 4 | + |
| 5 | +it("previews the first line up to 300 units without splitting an emoji", () => { |
| 6 | + expect(errorDetailsPreview(`${"a".repeat(299)}😀 more`)).toBe("a".repeat(299)); |
| 7 | + expect(errorDetailsPreview(`${"a".repeat(298)}😀 more`)).toBe(`${"a".repeat(298)}😀`); |
| 8 | + expect(errorDetailsPreview("TypeError: boom 🚀\n at render")).toBe("TypeError: boom 🚀"); |
| 9 | +}); |
Collapse file
Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { splitsSurrogatePair } from "@t3tools/shared/assistantCitations"; |
| 2 | + |
| 3 | +const PREVIEW_LIMIT = 300; |
| 4 | + |
| 5 | +export function errorDetailsPreview(details: string) { |
| 6 | + const firstLine = details.split("\n", 1)[0] ?? ""; |
| 7 | + return firstLine.slice( |
| 8 | + 0, |
| 9 | + splitsSurrogatePair(firstLine, PREVIEW_LIMIT) ? PREVIEW_LIMIT - 1 : PREVIEW_LIMIT, |
| 10 | + ); |
| 11 | +} |
Collapse file
Copy file name to clipboardExpand all lines: apps/mobile/src/components/RenderErrorBoundary.tsx +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@ import { ScrollView, View } from "react-native"; |
6 | 6 | import { AppText as Text } from "./ui/AppText"; |
7 | 7 | import { Button } from "./ui/Button"; |
8 | 8 | import { copyTextWithHaptic } from "../lib/copyTextWithHaptic"; |
| 9 | +import { errorDetailsPreview } from "./RenderErrorBoundary.logic"; |
9 | 10 |
|
10 | 11 | interface RenderErrorBoundaryProps { |
11 | 12 | readonly children: ReactNode; |
@@ -112,7 +113,7 @@ export function RenderFailureView( |
112 | 113 | <T>Try again. If it keeps happening, copy the details for a bug report.</T> |
113 | 114 | </Text> |
114 | 115 | <Text selectable className="text-center font-mono text-xs text-danger-foreground"> |
115 | | - {props.details.split("\n", 1)[0]?.slice(0, 300)} |
| 116 | + {errorDetailsPreview(props.details)} |
116 | 117 | </Text> |
117 | 118 | <View className="w-full max-w-xs gap-2"> |
118 | 119 | <Button label={gt("Try again")} onPress={props.retry} tone="primary" fullWidth /> |
|