Skip to content

Commit 57006dc

Browse files
committed
[dashboard, supervisor] Instead of auto restarting when we see a new instance, show state and provide controls
1 parent 6b00721 commit 57006dc

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

components/dashboard/src/start/StartWorkspace.tsx

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,26 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
268268
}
269269

270270
async onInstanceUpdate(workspaceInstance: WorkspaceInstance) {
271-
const startedInstanceId = this.state?.startedInstanceId;
272-
if (workspaceInstance.workspaceId !== this.props.workspaceId || startedInstanceId !== workspaceInstance.id) {
271+
if (workspaceInstance.workspaceId !== this.props.workspaceId) {
273272
return;
274273
}
275274

275+
// Here we filter out updates to instances we haven't started to avoid issues with updates coming in out-of-order
276+
// (e.g., multiple "stopped" events from the older instance, where we already started a fresh one after the first)
277+
// Only exception is when we do the switch from the "old" to the "new" one.
278+
const startedInstanceId = this.state?.startedInstanceId;
279+
if (startedInstanceId !== workspaceInstance.id) {
280+
// do we want to switch to "new" instance we just received an update for?
281+
const switchToNewInstance = this.state.workspaceInstance?.status.phase === "stopped" && workspaceInstance.status.phase !== "stopped";
282+
if (!switchToNewInstance) {
283+
return;
284+
}
285+
this.setState({
286+
startedInstanceId: workspaceInstance.id,
287+
workspaceInstance,
288+
});
289+
}
290+
276291
await this.ensureWorkspaceAuth(workspaceInstance.id);
277292

278293
// Redirect to workspaceURL if we are not yet running in an iframe.
@@ -337,7 +352,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
337352
const { error } = this.state;
338353
const isHeadless = this.state.workspace?.type !== 'regular';
339354
const isPrebuilt = WithPrebuild.is(this.state.workspace?.context);
340-
let phase = StartPhase.Preparing;
355+
let phase: StartPhase | undefined = StartPhase.Preparing;
341356
let title = undefined;
342357
let statusMessage = !!error ? undefined : <p className="text-base text-gray-400">Preparing workspace …</p>;
343358
const contextURL = ContextURL.getNormalizedURL(this.state.workspace)?.toString();
@@ -384,7 +399,27 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
384399
}
385400
if (!this.state.desktopIde) {
386401
phase = StartPhase.Running;
387-
statusMessage = <p className="text-base text-gray-400">Opening Workspace …</p>;
402+
403+
if (this.state.dontAutostart) {
404+
title = 'Running'
405+
phase = undefined; // hide the progress bar, as we're already running
406+
// in case we dontAutostart the IDE we have to provide controls to do so
407+
statusMessage = <div>
408+
<div className="flex space-x-3 items-center text-left rounded-xl m-auto px-4 h-16 w-72 mt-4 mb-2 bg-gray-100 dark:bg-gray-800">
409+
<div className="rounded-full w-3 h-3 text-sm bg-green-500">&nbsp;</div>
410+
<div>
411+
<p className="text-gray-700 dark:text-gray-200 font-semibold w-56 truncate">{this.state.workspaceInstance.workspaceId}</p>
412+
<a target="_parent" href={contextURL}><p className="w-56 truncate hover:text-blue-600 dark:hover:text-blue-400" >{contextURL}</p></a>
413+
</div>
414+
</div>
415+
<div className="mt-10 justify-center flex space-x-2">
416+
<a target="_parent" href={gitpodHostUrl.asDashboard().toString()}><button className="secondary">Go to Dashboard</button></a>
417+
<a target="_parent" href={gitpodHostUrl.asStart(this.props.workspaceId).toString() /** move over 'start' here to fetch fresh credentials in case this is an older tab */}><button>Open Workspace</button></a>
418+
</div>
419+
</div>;
420+
} else {
421+
statusMessage = <p className="text-base text-gray-400">Opening Workspace …</p>;
422+
}
388423
} else {
389424
phase = StartPhase.IdeReady;
390425
const openLink = this.state.desktopIde.link;

components/supervisor/frontend/src/index.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ const toStop = new DisposableCollection();
106106

107107
//#region current-frame
108108
let current: HTMLElement = loading.frame;
109-
let stopped = false;
110109
let desktopRedirected = false;
111110
const nextFrame = () => {
112111
const instance = gitpodServiceClient.info.latestInstance;
@@ -142,19 +141,6 @@ const toStop = new DisposableCollection();
142141
return document.body;
143142
}
144143
}
145-
if (instance.status.phase === 'stopped') {
146-
stopped = true;
147-
}
148-
if (stopped && (
149-
instance.status.phase === 'preparing' ||
150-
instance.status.phase === 'pending' ||
151-
instance.status.phase === 'creating' ||
152-
instance.status.phase === 'initializing')) {
153-
// reload the page if the workspace was restarted to ensure:
154-
// - graceful reconnection of IDEs
155-
// - new owner token is set
156-
window.location.href = startUrl.with({ search: "error=true" }).toString();
157-
}
158144
}
159145
return loading.frame;
160146
}

0 commit comments

Comments
 (0)