Skip to content

Commit 422b569

Browse files
committed
fix
1 parent b4aff7f commit 422b569

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/button/button.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useHotkeys } from "react-hotkeys-hook";
44
import Logo from "react:./logo-mark.svg";
55

66
import { useStorage } from "@plasmohq/storage/hook";
7+
import { Storage } from "@plasmohq/storage";
78

89
import { DEFAULT_GITPOD_ENDPOINT, EVENT_CURRENT_URL_CHANGED } from "~constants";
910
import { STORAGE_KEY_ADDRESS, STORAGE_KEY_ALWAYS_OPTIONS, STORAGE_KEY_NEW_TAB } from "~storage";
@@ -17,7 +18,7 @@ type Props = {
1718
urlTransformer?: (url: string) => string;
1819
};
1920
export const GitpodButton = ({ application, additionalClassNames, urlTransformer }: Props) => {
20-
const [address, setAddress] = useStorage<string>(STORAGE_KEY_ADDRESS);
21+
const [address] = useStorage<string>(STORAGE_KEY_ADDRESS);
2122
const [openInNewTab] = useStorage<boolean>(STORAGE_KEY_NEW_TAB, true);
2223
const [disableAutostart] = useStorage<boolean>(STORAGE_KEY_ALWAYS_OPTIONS, false);
2324
const [showDropdown, setShowDropdown] = useState(false);
@@ -39,9 +40,14 @@ export const GitpodButton = ({ application, additionalClassNames, urlTransformer
3940

4041
// if the user has no address configured, set it to the default endpoint
4142
useEffect(() => {
42-
if (!address) {
43-
setAddress(DEFAULT_GITPOD_ENDPOINT);
44-
}
43+
(async () => {
44+
// we don't use the useStorage hook because it does not offer a way see if the value is set (it could just be loading), meaning we could end up setting the default endpoint even if it's already set
45+
const storage = new Storage();
46+
const persistedAddress = await storage.get(STORAGE_KEY_ADDRESS);
47+
if (!persistedAddress) {
48+
await storage.set(STORAGE_KEY_ADDRESS, DEFAULT_GITPOD_ENDPOINT);
49+
}
50+
})();
4551
}, [address]);
4652

4753
const actions = useMemo(() => {

0 commit comments

Comments
 (0)