Skip to content

Commit df0a48f

Browse files
juliusmarmingecodex
andcommitted
fix(web): report preview action failures
Co-authored-by: codex <[email protected]>
1 parent 97e5cd3 commit df0a48f

3 files changed

Lines changed: 177 additions & 38 deletions

File tree

‎apps/web/src/components/preview/PreviewMoreMenu.tsx‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Menu, MenuItem, MenuPopup, MenuSeparator, MenuTrigger } from "~/compone
77
import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
88

99
import { previewBridge } from "./previewBridge";
10+
import { reportPreviewActionFailure } from "./reportPreviewActionFailure";
1011

1112
interface Props {
1213
/** Active preview tab id. Tab-targeting actions are disabled without it. */
@@ -30,9 +31,11 @@ export function PreviewMoreMenu({ tabId, hasWebContents, zoomFactor }: Props) {
3031
if (!previewBridge) return null;
3132
const bridge = previewBridge;
3233
const tabDisabled = !tabId || !hasWebContents;
33-
const callTab = (op: (tabId: string) => Promise<void>) => () => {
34+
const callTab = (operation: string, op: (tabId: string) => Promise<void>) => () => {
3435
if (!tabId) return;
35-
void op(tabId).catch(() => undefined);
36+
void op(tabId).catch((cause) => {
37+
reportPreviewActionFailure({ operation, tabId }, cause);
38+
});
3639
};
3740

3841
const zoomLabel = `${Math.round(zoomFactor * 100)}%`;
@@ -53,10 +56,10 @@ export function PreviewMoreMenu({ tabId, hasWebContents, zoomFactor }: Props) {
5356
<TooltipPopup>More</TooltipPopup>
5457
</Tooltip>
5558
<MenuPopup align="end" sideOffset={6} className="min-w-56">
56-
<MenuItem onClick={callTab(bridge.hardReload)} disabled={tabDisabled}>
59+
<MenuItem onClick={callTab("hard-reload", bridge.hardReload)} disabled={tabDisabled}>
5760
Hard reload
5861
</MenuItem>
59-
<MenuItem onClick={callTab(bridge.openDevTools)} disabled={tabDisabled}>
62+
<MenuItem onClick={callTab("open-devtools", bridge.openDevTools)} disabled={tabDisabled}>
6063
Open DevTools
6164
</MenuItem>
6265
{/*
@@ -75,7 +78,7 @@ export function PreviewMoreMenu({ tabId, hasWebContents, zoomFactor }: Props) {
7578
variant="outline"
7679
size="icon-xs"
7780
type="button"
78-
onClick={callTab(bridge.zoomOut)}
81+
onClick={callTab("zoom-out", bridge.zoomOut)}
7982
aria-label="Zoom out"
8083
disabled={tabDisabled}
8184
>
@@ -88,7 +91,7 @@ export function PreviewMoreMenu({ tabId, hasWebContents, zoomFactor }: Props) {
8891
variant="outline"
8992
size="icon-xs"
9093
type="button"
91-
onClick={callTab(bridge.zoomIn)}
94+
onClick={callTab("zoom-in", bridge.zoomIn)}
9295
aria-label="Zoom in"
9396
disabled={tabDisabled}
9497
>
@@ -98,7 +101,7 @@ export function PreviewMoreMenu({ tabId, hasWebContents, zoomFactor }: Props) {
98101
variant="ghost"
99102
size="icon-xs"
100103
type="button"
101-
onClick={callTab(bridge.resetZoom)}
104+
onClick={callTab("reset-zoom", bridge.resetZoom)}
102105
aria-label="Reset zoom"
103106
disabled={tabDisabled}
104107
>
@@ -107,10 +110,22 @@ export function PreviewMoreMenu({ tabId, hasWebContents, zoomFactor }: Props) {
107110
</span>
108111
</MenuItem>
109112
<MenuSeparator />
110-
<MenuItem onClick={() => void bridge.clearCookies().catch(() => undefined)}>
113+
<MenuItem
114+
onClick={() =>
115+
void bridge.clearCookies().catch((cause) => {
116+
reportPreviewActionFailure({ operation: "clear-cookies" }, cause);
117+
})
118+
}
119+
>
111120
Clear cookies
112121
</MenuItem>
113-
<MenuItem onClick={() => void bridge.clearCache().catch(() => undefined)}>
122+
<MenuItem
123+
onClick={() =>
124+
void bridge.clearCache().catch((cause) => {
125+
reportPreviewActionFailure({ operation: "clear-cache" }, cause);
126+
})
127+
}
128+
>
114129
Clear cache
115130
</MenuItem>
116131
</MenuPopup>

0 commit comments

Comments
 (0)