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