Skip to content
TypeScript

perf(web): capture shortcut config compile with the React Compiler (#20511)

Julius Marminge350127040a3b
diff --git a/apps/web/reactCompiledFiles.ts b/apps/web/reactCompiledFiles.ts
index 2ef78c73033..c8ed792fa3b 100644
--- a/apps/web/reactCompiledFiles.ts
+++ b/apps/web/reactCompiledFiles.ts
@@ -86,4 +86,5 @@ export const REACT_COMPILED_FILES = [
"apps/web/src/components/settings/DeviceHostsSettings.tsx",
"apps/web/src/components/settings/ProjectSettingsPanel.tsx",
"apps/web/src/components/settings/AcpSessionManagementSection.tsx",
+ "apps/web/src/components/settings/CaptureShortcutConfig.tsx",
] as const;
diff --git a/apps/web/src/components/settings/CaptureShortcutConfig.tsx b/apps/web/src/components/settings/CaptureShortcutConfig.tsx
index 3b9b6873bb0..11e12114e43 100644
--- a/apps/web/src/components/settings/CaptureShortcutConfig.tsx
+++ b/apps/web/src/components/settings/CaptureShortcutConfig.tsx
@@ -7,7 +7,9 @@ import {
import { parseKeybindingShortcut } from "@t3tools/shared/keybindings";
import { FileDiff } from "@pierre/diffs/react";
import { parseDiffFromFile } from "@pierre/diffs";
-import { useMemo, useState } from "react";
+import { settlePromise } from "@t3tools/client-runtime/state/runtime";
+import * as Cause from "effect/Cause";
+import { useState } from "react";
import { getDesktopSnapShotBridge } from "../../lib/desktopSnapShot";
import { resolveDiffThemeName } from "../../lib/diffRendering";
import { useTheme } from "../../hooks/useTheme";
@@ -69,16 +71,13 @@ export function CaptureShortcutConfig({
},
});
const actionBusy = busy || recorder.recording;
- const diff = useMemo(
- () =>
- preview && changed
- ? parseDiffFromFile(
- { name: preview.path, contents: preview.before },
- { name: preview.path, contents: preview.after },
- )
- : null,
- [preview, changed],
- );
+ const diff =
+ preview && changed
+ ? parseDiffFromFile(
+ { name: preview.path, contents: preview.before },
+ { name: preview.path, contents: preview.after },
+ )
+ : null;
const begin = (phase: "reading" | "writing") => {
setWorking(phase);
onBusyChange?.(true);
@@ -94,28 +93,29 @@ export function CaptureShortcutConfig({
setPreview(null);
setResult(null);
setCustomFile(chooseFile);
- try {
- setPreview(
- await bridge.previewSnapShotConfig({
- operation,
- chooseFile,
- ...(keys?.trim() ? { shortcut: keys.trim() } : {}),
- }),
- );
- } catch (cause) {
+ const previewed = await settlePromise(() =>
+ bridge.previewSnapShotConfig!({
+ operation,
+ chooseFile,
+ ...(keys?.trim() ? { shortcut: keys.trim() } : {}),
+ }),
+ );
+ if (previewed._tag === "Success") {
+ setPreview(previewed.value);
+ } else {
+ const cause = Cause.squash(previewed.cause);
setError({
message: "Couldn't prepare the changes. Check Advanced for help.",
...(cause instanceof Error ? { detail: cause.message } : {}),
});
- } finally {
- end();
}
+ end();
};
const apply = async () => {
if (actionBusy || !preview || !bridge?.applySnapShotConfig) return;
begin("writing");
- try {
- const applied = await bridge.applySnapShotConfig(preview.id);
+ const saved = await settlePromise(async () => {
+ const applied = await bridge.applySnapShotConfig!(preview.id);
setResult(applied);
await onSaved?.();
if (!applied.warning && preview.operation === "install" && onComplete) {
@@ -126,15 +126,16 @@ export function CaptureShortcutConfig({
});
await onComplete();
}
- } catch (cause) {
+ });
+ if (saved._tag === "Failure") {
+ const cause = Cause.squash(saved.cause);
setError({
message: "Couldn't save your shortcut. Review the changes and try again.",
...(cause instanceof Error ? { detail: cause.message } : {}),
});
setPreview(null);
- } finally {
- end();
}
+ end();
};
return (