From 2d28ee9e42327c6091a85eca08358f1132c8075b Mon Sep 17 00:00:00 2001 From: Evan Krause Date: Thu, 9 May 2024 09:52:23 -0700 Subject: [PATCH] Fix isl not detecting workspace folder changes without reloading Summary: It seems we were not properly subscribing to changes in the vscode workspace folders. We used `onConnectOrReconnect` inside the lazyAtom, which means it was not triggered on first connect. Since reconnects don't happen in most cases (maybe never for vscode connection...?), it would never actually subscribe. Instead, we could either move this to a not lazy atom, or make it just call the subscribe directly. I opt to make the atom not lazy, since we use this in the cwdSelector immediately on startup, there's no real use having it be lazy. Maybe that made sense when the cwd dropdown didn't use this state. Reviewed By: quark-zju Differential Revision: D57136047 fbshipit-source-id: 8298b8b94b06e109f78240d20cb42014f3d18e00 --- addons/isl/src/CwdSelector.tsx | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/addons/isl/src/CwdSelector.tsx b/addons/isl/src/CwdSelector.tsx index 1f788181f3f64..6d98d99fddb74 100644 --- a/addons/isl/src/CwdSelector.tsx +++ b/addons/isl/src/CwdSelector.tsx @@ -25,7 +25,7 @@ import {lazyAtom, writeAtom} from './jotaiUtils'; import {serverCwd} from './repositoryData'; import {repositoryInfo} from './serverAPIState'; import {registerCleanup, registerDisposable} from './utils'; -import {useAtomValue} from 'jotai'; +import {atom, useAtomValue} from 'jotai'; import {Icon} from 'shared/Icon'; import {KeyCode, Modifier} from 'shared/KeyboardShortcuts'; import {basename} from 'shared/utils'; @@ -60,19 +60,16 @@ function getRepoLabel(repoRoot: AbsolutePath, cwd: string) { return repoBasename + repoRelativeCwd; } -export const availableCwds = lazyAtom>(() => { - // Only request `subscribeToAvailableCwds` when first read the atom. - registerCleanup( - availableCwds, - serverAPI.onConnectOrReconnect(() => { - serverAPI.postMessage({ - type: 'platform/subscribeToAvailableCwds', - }); - }), - import.meta.hot, - ); - return []; -}, []); +export const availableCwds = atom>([]); +registerCleanup( + availableCwds, + serverAPI.onConnectOrReconnect(() => { + serverAPI.postMessage({ + type: 'platform/subscribeToAvailableCwds', + }); + }), + import.meta.hot, +); registerDisposable( availableCwds,