From a8804944378ef5284dc59b4ad2936071e64b0218 Mon Sep 17 00:00:00 2001 From: Flleeppyy Date: Mon, 15 Jun 2026 18:25:00 -0700 Subject: [PATCH] fixies! --- .../FeedbackContextProvider.tsx | 80 +++++++++++-------- .../OnboardingContextProvider.tsx | 2 +- src/contextProviders/useServerState.ts | 3 +- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/contextProviders/FeedbackContextProvider.tsx b/src/contextProviders/FeedbackContextProvider.tsx index d3ef844..e1f27c3 100644 --- a/src/contextProviders/FeedbackContextProvider.tsx +++ b/src/contextProviders/FeedbackContextProvider.tsx @@ -1,8 +1,10 @@ import { createContext, type PropsWithChildren, + useCallback, useContext, useEffect, + useMemo, useRef, useState, } from "react"; @@ -195,30 +197,33 @@ export function FeedbackContextProvider(props: PropsWithChildren) { }); }; - const pushSnackbar = (severity: SnackbarSeverity, input: FeedbackInput) => { + const pushSnackbar = useCallback((severity: SnackbarSeverity, input: FeedbackInput) => { pushSnackbarItem({ id: createId(), severity, message: input.message, detail: input.detail, }); - }; - - const showError = (input: ErrorReportInput) => { - pushError({ - id: createId(), - severity: "error", - source: input.source, - userMessage: input.userMessage, - code: input.code, - technicalDetails: input.technicalDetails, - correlationId: input.correlationId, - isTransient: input.isTransient ?? true, - timestamp: new Date().toISOString(), - }, input.dedupe ?? true); - }; + }, []); - const showFatal = (input: ErrorReportInput) => { + const showError = useCallback((input: ErrorReportInput) => { + pushError( + { + id: createId(), + severity: "error", + source: input.source, + userMessage: input.userMessage, + code: input.code, + technicalDetails: input.technicalDetails, + correlationId: input.correlationId, + isTransient: input.isTransient ?? true, + timestamp: new Date().toISOString(), + }, + input.dedupe ?? true, + ); + }, []) + + const showFatal = useCallback((input: ErrorReportInput) => { pushError({ id: createId(), severity: "fatal", @@ -230,16 +235,16 @@ export function FeedbackContextProvider(props: PropsWithChildren) { isTransient: false, timestamp: new Date().toISOString(), }, input.dedupe ?? true); - }; + }, []) - const showSuccess = (input: FeedbackInput) => pushSnackbar("success", input); - const showInfo = (input: FeedbackInput) => pushSnackbar("info", input); - const showWarning = (input: FeedbackInput) => pushSnackbar("warning", input); + const showSuccess = useCallback((input: FeedbackInput) => pushSnackbar("success", input), []) + const showInfo = useCallback((input: FeedbackInput) => pushSnackbar("info", input), []) + const showWarning = useCallback((input: FeedbackInput) => pushSnackbar("warning", input), []) - const clearFatal = () => { + const clearFatal = useCallback(() => { setFatalError(null); setCopyFeedback(null); - }; + }, []); const openLogDirectory = () => { void invoke("open_log_directory"); @@ -347,15 +352,26 @@ export function FeedbackContextProvider(props: PropsWithChildren) { }; }, []); - const value: FeedbackContextValue = { - showError, - showFatal, - clearFatal, - recentErrors, - showSuccess, - showInfo, - showWarning, - }; + const value: FeedbackContextValue = useMemo( + () => ({ + showError, + showFatal, + clearFatal, + recentErrors, + showSuccess, + showInfo, + showWarning, + }), + [ + showError, + showFatal, + clearFatal, + recentErrors, + showSuccess, + showInfo, + showWarning, + ], + ); const fatalTrace = fatalError ? buildTrace(fatalError) : ""; diff --git a/src/contextProviders/OnboardingContextProvider.tsx b/src/contextProviders/OnboardingContextProvider.tsx index 94ed48d..620c3a3 100644 --- a/src/contextProviders/OnboardingContextProvider.tsx +++ b/src/contextProviders/OnboardingContextProvider.tsx @@ -105,7 +105,7 @@ export function OnboardingContextProvider(props: OnboardingContextProviderProps) }); } })(); - }, [activeStep, showError]); + }, [activeStep]); const advanceQueue = () => { setPendingSteps((prev) => prev.slice(1)); diff --git a/src/contextProviders/useServerState.ts b/src/contextProviders/useServerState.ts index 15c4aed..0dd96f9 100644 --- a/src/contextProviders/useServerState.ts +++ b/src/contextProviders/useServerState.ts @@ -124,7 +124,6 @@ export function useServerState(options: UseServerStateOptions) { } if (!result.success) { - setServers((prev) => prev ?? []); showError({ source: "frontend.servers.get-servers", userMessage: "Failed to refresh server list.", @@ -183,7 +182,7 @@ export function useServerState(options: UseServerStateOptions) { clearTimeout(timeoutId); } }; - }, [isServersPageActive, showError]); + }, [isServersPageActive]); // Subscribe to real-time events useEffect(() => {