@@ -36,6 +36,7 @@ import {
36
36
import { PartialMessage } from "@bufbuild/protobuf" ;
37
37
import { trackEvent } from "../Analytics" ;
38
38
import { fromWorkspaceName } from "../workspaces/RenameWorkspaceModal" ;
39
+ import { LinkButton } from "@podkit/buttons/LinkButton" ;
39
40
40
41
const sessionId = v4 ( ) ;
41
42
@@ -102,6 +103,14 @@ export interface StartWorkspaceState {
102
103
ideOptions ?: IDEOptions ;
103
104
isSSHModalVisible ?: boolean ;
104
105
ownerToken ?: string ;
106
+ /**
107
+ * Set to prevent multiple redirects to the same URL when the User Agent ignores our wish to open links in the same tab (by setting window.location.href).
108
+ */
109
+ redirected ?: boolean ;
110
+ /**
111
+ * Determines whether `redirected` has been `true` for long enough to display our "new tab" info banner without racing with same-tab redirection in regular setups
112
+ */
113
+ showRedirectMessage ?: boolean ;
105
114
}
106
115
107
116
// TODO: use Function Components
@@ -183,7 +192,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
183
192
this . toDispose . dispose ( ) ;
184
193
}
185
194
186
- componentDidUpdate ( prevPros : StartWorkspaceProps , prevState : StartWorkspaceState ) {
195
+ componentDidUpdate ( _prevProps : StartWorkspaceProps , prevState : StartWorkspaceState ) {
187
196
const newPhase = this . state ?. workspace ?. status ?. phase ?. name ;
188
197
const oldPhase = prevState . workspace ?. status ?. phase ?. name ;
189
198
const type = this . state . workspace ?. spec ?. type === WorkspaceSpec_WorkspaceType . PREBUILD ? "prebuild" : "regular" ;
@@ -458,11 +467,20 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
458
467
}
459
468
460
469
redirectTo ( url : string ) {
470
+ if ( this . state . redirected ) {
471
+ console . info ( "Prevented another redirect" , { url } ) ;
472
+ return ;
473
+ }
461
474
if ( this . props . runsInIFrame ) {
462
475
this . ideFrontendService ?. relocate ( url ) ;
463
476
} else {
464
477
window . location . href = url ;
465
478
}
479
+
480
+ this . setState ( { redirected : true } ) ;
481
+ setTimeout ( ( ) => {
482
+ this . setState ( { showRedirectMessage : true } ) ;
483
+ } , 2000 ) ;
466
484
}
467
485
468
486
private openDesktopLink ( link : string ) {
@@ -503,7 +521,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
503
521
return < ImageBuildView workspaceId = { this . state . workspace . id } /> ;
504
522
505
523
// Pending means the workspace does not yet consume resources in the cluster, but rather is looking for
506
- // some space within the cluster. If for example the cluster needs to scale up to accomodate the
524
+ // some space within the cluster. If for example the cluster needs to scale up to accommodate the
507
525
// workspace, the workspace will be in Pending state until that happened.
508
526
case WorkspacePhase_Phase . PENDING :
509
527
phase = StartPhase . Preparing ;
@@ -746,6 +764,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
746
764
) ;
747
765
break ;
748
766
}
767
+
749
768
return (
750
769
< StartPage
751
770
phase = { phase }
@@ -755,6 +774,30 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
755
774
workspaceId = { this . props . workspaceId }
756
775
>
757
776
{ statusMessage }
777
+ { this . state . showRedirectMessage && (
778
+ < >
779
+ < Alert type = "info" className = "mt-4 w-112" >
780
+ We redirected you to your workspace, but your browser probably opened it in another tab.
781
+ </ Alert >
782
+
783
+ < div className = "mt-4 justify-center flex space-x-2" >
784
+ < LinkButton href = { gitpodHostUrl . asWorkspacePage ( ) . toString ( ) } target = "_self" isExternalUrl >
785
+ Go to Dashboard
786
+ </ LinkButton >
787
+ { this . state . workspace ?. status ?. workspaceUrl &&
788
+ this . state . workspace . status . phase ?. name === WorkspacePhase_Phase . RUNNING && (
789
+ < LinkButton
790
+ variant = { "secondary" }
791
+ href = { this . state . workspace . status . workspaceUrl }
792
+ target = "_self"
793
+ isExternalUrl
794
+ >
795
+ Re-open Workspace
796
+ </ LinkButton >
797
+ ) }
798
+ </ div >
799
+ </ >
800
+ ) }
758
801
</ StartPage >
759
802
) ;
760
803
}
0 commit comments