Skip to content

Commit d22794f

Browse files
fix polling of running state
1 parent 8b5a4f0 commit d22794f

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codesandbox/sdk",
3-
"version": "2.0.0-rc.3",
3+
"version": "2.0.0-rc.4",
44
"description": "The CodeSandbox SDK",
55
"author": "CodeSandbox",
66
"license": "MIT",

src/bin/main.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import { hostTokensCommand } from "./commands/hostTokens";
99
import { Dashboard } from "./ui/Dashboard";
1010
import React from "react";
1111
import { SDKProvider } from "./ui/sdkContext";
12-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
12+
import {
13+
focusManager,
14+
onlineManager,
15+
QueryClient,
16+
QueryClientProvider,
17+
} from "@tanstack/react-query";
1318

1419
if (process.argv.length === 2) {
1520
// Clear the screen before rendering the dashboard

src/bin/ui/Dashboard.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,24 @@ export function Dashboard() {
2525
const runningVmsQuery = useQuery({
2626
queryKey: ["runningVms"],
2727
queryFn: getRunningVms,
28-
refetchInterval: 2000, // Poll every 2 seconds
2928
});
3029

3130
const [sandboxId, setSandboxId] = useState("");
3231
const [showSandbox, setShowSandbox] = useState(false);
3332
const [isFocused, setIsFocused] = useState(true);
3433
const [stdoutWidth, stdoutHeight] = useTerminalSize();
3534

35+
useEffect(() => {
36+
// have to manually do this because of environment
37+
const interval = setInterval(() => {
38+
runningVmsQuery.refetch();
39+
}, 2000);
40+
41+
return () => {
42+
clearInterval(interval);
43+
};
44+
}, []);
45+
3646
useInput((input, key) => {
3747
if (!showSandbox) {
3848
if (key.return) {
@@ -49,7 +59,7 @@ export function Dashboard() {
4959
});
5060

5161
if (showSandbox) {
52-
const state = runningVmsQuery.isFetching
62+
const state = runningVmsQuery.isLoading
5363
? "PENDING"
5464
: runningVmsQuery.data?.vms.find((vm) => vm.id === sandboxId)
5565
? "RUNNING"

0 commit comments

Comments
 (0)