History

fix(settings): keep the WSL recovery row visible during retry

Addresses a Cursor Bugbot finding: loadWslState() cleared the error up front, so clicking Retry made the error/retry row vanish (renderWslRow only shows it when !desktopWslState and desktopWslError) until the IPC settled. Clear the error only on success instead, so it persists across an in-flight retry, and add a loading flag so the Retry button shows "Retrying..." and is disabled while in flight.

Josh Gratton committed 4 months ago

Commit 2a3cdd51 parent 72a648a1 file · +22 −9Browse files

Unified · Split

apps/web/src/components/settings/ConnectionsSettings.tsx+22−9
@@ -2013,6 +2013,7 @@ export function ConnectionsSettings() { · 2012 unmodified lines
2013 const [desktopWslState, setDesktopWslState] = useState<DesktopWslState | null>(null);2013 const [desktopWslState, setDesktopWslState] = useState<DesktopWslState | null>(null);
2014 const [isUpdatingWslBackend, setIsUpdatingWslBackend] = useState(false);2014 const [isUpdatingWslBackend, setIsUpdatingWslBackend] = useState(false);
2015 const [desktopWslError, setDesktopWslError] = useState<string | null>(null);2015 const [desktopWslError, setDesktopWslError] = useState<string | null>(null);
2016 const [isLoadingWslState, setIsLoadingWslState] = useState(false);
2016 // Pending WSL setting change waiting on user confirmation. Set when2017 // Pending WSL setting change waiting on user confirmation. Set when
2017 // the user tries a destructive change (disable, switch distro,2018 // the user tries a destructive change (disable, switch distro,
2018 // toggle wsl-only) while the WSL backend has saved-env state on this2019 // toggle wsl-only) while the WSL backend has saved-env state on this
@@ -2801,21 +2802,26 @@ export function ConnectionsSettings() { · 782 unmodified lines
2801 [desktopBridge],2802 [desktopBridge],
2802 );2803 );
2803 2804
2804 // Load the WSL backend state from the desktop bridge. Clears any prior error2805 // Load the WSL backend state from the desktop bridge. Clears the error only on
2805 // up front so a stale failure message can't linger after a later success, and2806 // success, so a failed load's message stays visible (including across an
2806 // is reused by the retry control in renderWslRow.2807 // in-flight retry, rather than the row flickering away), and tracks a loading
2808 // flag for the retry control. Reused by the retry control in renderWslRow.
2807 const loadWslState = useCallback(() => {2809 const loadWslState = useCallback(() => {
2808 if (!desktopBridge) {2810 if (!desktopBridge) {
2809 return;2811 return;
2810 }2812 }
2811 setDesktopWslError(null);2813 setIsLoadingWslState(true);
2812 void desktopBridge2814 void desktopBridge
2813 .getWslState()2815 .getWslState()
2814 .then((state) => {2816 .then((state) => {
2815 setDesktopWslState(state);2817 setDesktopWslState(state);
2818 setDesktopWslError(null);
2816 })2819 })
2817 .catch((error: unknown) => {2820 .catch((error: unknown) => {
2818 setDesktopWslError(error instanceof Error ? error.message : "Failed to load WSL state.");2821 setDesktopWslError(error instanceof Error ? error.message : "Failed to load WSL state.");
2822 })
2823 .finally(() => {
2824 setIsLoadingWslState(false);
2819 });2825 });
2820 }, [desktopBridge]);2826 }, [desktopBridge]);
2821 2827
@@ -2960,9 +2966,11 @@ export function ConnectionsSettings() { · 138 unmodified lines
2960 2966
2961 const renderWslRow = () => {2967 const renderWslRow = () => {
2962 if (!desktopWslState) {2968 if (!desktopWslState) {
2963 // The initial getWslState() load failed: surface the error with a retry2969 // A load failed: keep a recovery row (with retry) visible instead of
2964 // rather than hiding the section silently. With no error we simply haven't2970 // silently hiding the section. The error persists across an in-flight
2965 // loaded yet (or WSL management isn't available), so render nothing.2971 // retry so the row doesn't flicker away, and the button reflects the
2972 // loading state. With no error we simply haven't loaded yet (or WSL
2973 // management isn't available), so render nothing.
2966 if (desktopWslError && canManageLocalBackend) {2974 if (desktopWslError && canManageLocalBackend) {
2967 return (2975 return (
2968 <SettingsRow2976 <SettingsRow
@@ -2970,8 +2978,13 @@ export function ConnectionsSettings() { · 1 unmodified line
2970 description="Couldn't load the WSL backend state."2978 description="Couldn't load the WSL backend state."
2971 status={<span className="block text-destructive">{desktopWslError}</span>}2979 status={<span className="block text-destructive">{desktopWslError}</span>}
2972 control={2980 control={
2973 <Button size="xs" variant="outline" onClick={loadWslState}>2981 <Button
2974 Retry2982 size="xs"
2983 variant="outline"
2984 onClick={loadWslState}
2985 disabled={isLoadingWslState}
2986 >
2987 {isLoadingWslState ? "Retrying…" : "Retry"}
2975 </Button>2988 </Button>
2976 }2989 }
2977 />2990 />

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t