Skip to content
TypeScript

perf(web): diagnostics settings compile with the React Compiler (#20507)

Julius Marminge123dc2450484
diff --git a/apps/web/reactCompiledFiles.ts b/apps/web/reactCompiledFiles.ts
index ec6a37efc24..b2235d3bb77 100644
--- a/apps/web/reactCompiledFiles.ts
+++ b/apps/web/reactCompiledFiles.ts
@@ -82,4 +82,5 @@ export const REACT_COMPILED_FILES = [
"apps/web/src/components/settings/NotificationSettings.tsx",
"apps/web/src/components/settings/ProviderSetupSection.tsx",
"apps/web/src/components/settings/StorageSettings.tsx",
+ "apps/web/src/components/settings/DiagnosticsSettings.tsx",
] as const;
diff --git a/apps/web/src/components/settings/DiagnosticsSettings.tsx b/apps/web/src/components/settings/DiagnosticsSettings.tsx
index e570f672a1f..277fc731f76 100644
--- a/apps/web/src/components/settings/DiagnosticsSettings.tsx
+++ b/apps/web/src/components/settings/DiagnosticsSettings.tsx
@@ -11,7 +11,7 @@ import {
isAtomCommandInterrupted,
squashAtomCommandFailure,
} from "@t3tools/client-runtime/state/runtime";
-import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
+import { useEffect, useRef, useState, type ReactNode } from "react";
import type {
ServerProcessDiagnosticsEntry,
ServerProcessResourceHistorySummary,
@@ -299,6 +299,28 @@ function ProcessNameCell({
);
}
+function visibleProcessTree(
+ processes: ReadonlyArray<ServerProcessDiagnosticsEntry>,
+ collapsedPids: ReadonlySet<number>,
+) {
+ const visible: ServerProcessDiagnosticsEntry[] = [];
+ let hiddenChildDepth: number | null = null;
+
+ for (const process of processes) {
+ if (hiddenChildDepth !== null) {
+ if (process.depth > hiddenChildDepth) continue;
+ hiddenChildDepth = null;
+ }
+
+ visible.push(process);
+ if (collapsedPids.has(process.pid)) {
+ hiddenChildDepth = process.depth;
+ }
+ }
+
+ return visible;
+}
+
function ProcessDiagnosticsTable({
processes,
canMaintainEnvironment,
@@ -313,26 +335,9 @@ function ProcessDiagnosticsTable({
emptyLabel?: string;
}) {
const [collapsedPids, setCollapsedPids] = useState<ReadonlySet<number>>(() => new Set());
- const visibleProcesses = useMemo(() => {
- const visible: ServerProcessDiagnosticsEntry[] = [];
- let hiddenChildDepth: number | null = null;
-
- for (const process of processes) {
- if (hiddenChildDepth !== null) {
- if (process.depth > hiddenChildDepth) continue;
- hiddenChildDepth = null;
- }
-
- visible.push(process);
- if (collapsedPids.has(process.pid)) {
- hiddenChildDepth = process.depth;
- }
- }
+ const visibleProcesses = visibleProcessTree(processes, collapsedPids);
- return visible;
- }, [collapsedPids, processes]);
-
- const toggleProcess = useCallback((pid: number) => {
+ const toggleProcess = (pid: number) => {
setCollapsedPids((previous) => {
const next = new Set(previous);
if (next.has(pid)) {
@@ -342,7 +347,7 @@ function ProcessDiagnosticsTable({
}
return next;
});
- }, []);
+ };
return (
<div className="border-t border-border/60">
@@ -783,7 +788,7 @@ export function DiagnosticsSettingsPanel() {
};
}, [environmentId]);
- const openLogsDirectory = useCallback(() => {
+ const openLogsDirectory = () => {
const logsDirectoryPath = observability?.logsDirectoryPath ?? null;
if (!logsDirectoryPath) return;
@@ -806,7 +811,7 @@ export function DiagnosticsSettingsPanel() {
);
}
})();
- }, [environmentId, observability?.logsDirectoryPath, openInEditor]);
+ };
const isInitialLoading = isPending && data === null;
const isProcessInitialLoading = isProcessPending && processData === null;
@@ -824,104 +829,97 @@ export function DiagnosticsSettingsPanel() {
) {
setExportFormEnvironmentId(environmentId);
}
- const signalProcess = useCallback(
- async (pid: number, signal: ServerProcessSignal) => {
- const targetEnvironmentId = environmentIdRef.current;
- const process = processDataRef.current?.processes.find((entry) => entry.pid === pid);
- if (
- targetEnvironmentId === null ||
- process === undefined ||
- !readEnvironmentScope(targetEnvironmentId, AuthEnvironmentMaintainScope)
- )
- return;
- if (signalingPidRef.current !== null) return;
- signalingPidRef.current = pid;
- setSignalingPid(pid);
- const clearSignaling = () => {
- signalingPidRef.current = null;
- setSignalingPid(null);
- };
- if (signal === "SIGKILL") {
- let confirmed = false;
- try {
- confirmed = await ensureLocalApi().dialogs.confirm(
- `Send SIGKILL to process ${pid}? This cannot be handled by the process.`,
- { variant: "destructive" },
- );
- } catch (error) {
- clearSignaling();
- toastManager.add({
- type: "error",
- title: "Could not confirm signal",
- description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
- });
- return;
- }
- if (!confirmed) {
- clearSignaling();
- return;
- }
- }
- const currentEnvironmentId = environmentIdRef.current;
- if (
- currentEnvironmentId === null ||
- currentEnvironmentId !== targetEnvironmentId ||
- !readEnvironmentScope(currentEnvironmentId, AuthEnvironmentMaintainScope)
- ) {
+ const signalProcess = async (pid: number, signal: ServerProcessSignal) => {
+ const targetEnvironmentId = environmentIdRef.current;
+ const process = processDataRef.current?.processes.find((entry) => entry.pid === pid);
+ if (
+ targetEnvironmentId === null ||
+ process === undefined ||
+ !readEnvironmentScope(targetEnvironmentId, AuthEnvironmentMaintainScope)
+ )
+ return;
+ if (signalingPidRef.current !== null) return;
+ signalingPidRef.current = pid;
+ setSignalingPid(pid);
+ const clearSignaling = () => {
+ signalingPidRef.current = null;
+ setSignalingPid(null);
+ };
+ if (signal === "SIGKILL") {
+ let confirmed = false;
+ try {
+ confirmed = await ensureLocalApi().dialogs.confirm(
+ `Send SIGKILL to process ${pid}? This cannot be handled by the process.`,
+ { variant: "destructive" },
+ );
+ } catch (error) {
clearSignaling();
+ toastManager.add({
+ type: "error",
+ title: "Could not confirm signal",
+ description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
+ });
return;
}
- if (
- processDataRef.current?.processes.find((entry) => entry.pid === pid)?.startTimeMs !==
- process.startTimeMs
- ) {
+ if (!confirmed) {
clearSignaling();
return;
}
+ }
+ const currentEnvironmentId = environmentIdRef.current;
+ if (
+ currentEnvironmentId === null ||
+ currentEnvironmentId !== targetEnvironmentId ||
+ !readEnvironmentScope(currentEnvironmentId, AuthEnvironmentMaintainScope)
+ ) {
+ clearSignaling();
+ return;
+ }
+ if (
+ processDataRef.current?.processes.find((entry) => entry.pid === pid)?.startTimeMs !==
+ process.startTimeMs
+ ) {
+ clearSignaling();
+ return;
+ }
- try {
- const result = await signalServerProcess({
- environmentId: targetEnvironmentId,
- input: { pid, startTimeMs: process.startTimeMs, signal },
+ const result = await signalServerProcess({
+ environmentId: targetEnvironmentId,
+ input: { pid, startTimeMs: process.startTimeMs, signal },
+ });
+ clearSignaling();
+ if (result._tag === "Failure") {
+ if (!isAtomCommandInterrupted(result)) {
+ const error = squashAtomCommandFailure(result);
+ toastManager.add({
+ type: "error",
+ title: `Could not send ${signal}`,
+ description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
});
- if (result._tag === "Failure") {
- if (!isAtomCommandInterrupted(result)) {
- const error = squashAtomCommandFailure(result);
- toastManager.add({
- type: "error",
- title: `Could not send ${signal}`,
- description: error instanceof Error ? error.message : `Failed to send ${signal}.`,
- });
- }
- return;
- }
- if (!result.value.signaled) {
- const message = Option.getOrUndefined(result.value.message);
- refreshProcesses();
- if (isStaleProcessSignalMessage(message)) {
- toastManager.add({
- type: "info",
- title: "Process already exited",
- description:
- "The process is not a child of the T3 Server. It might already have exited.",
- });
- return;
- }
-
- toastManager.add({
- type: "error",
- title: `Could not send ${signal}`,
- description: message ?? `Failed to send ${signal}.`,
- });
- return;
- }
- refreshProcesses();
- } finally {
- clearSignaling();
}
- },
- [refreshProcesses, signalServerProcess],
- );
+ return;
+ }
+ if (!result.value.signaled) {
+ const message = Option.getOrUndefined(result.value.message);
+ refreshProcesses();
+ if (isStaleProcessSignalMessage(message)) {
+ toastManager.add({
+ type: "info",
+ title: "Process already exited",
+ description: "The process is not a child of the T3 Server. It might already have exited.",
+ });
+ return;
+ }
+
+ toastManager.add({
+ type: "error",
+ title: `Could not send ${signal}`,
+ description: message ?? `Failed to send ${signal}.`,
+ });
+ return;
+ }
+ refreshProcesses();
+ };
const processDiagnosticsError = processData ? Option.getOrNull(processData.error) : null;
const processResourceError = resourceData ? Option.getOrNull(resourceData.error) : null;