Skip to content

Commit 020a30b

Browse files
authored
fix: proper window.location redirects for cloud sandboxes and branches (#6994)
1 parent 7b64d3e commit 020a30b

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

packages/app/src/app/pages/Dashboard/Components/Sandbox/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ const GenericSandbox = ({ isScrolling, item, page }: GenericSandboxProps) => {
198198
if (sandboxAnalyticsEvent) {
199199
trackImprovedDashboardEvent(sandboxAnalyticsEvent);
200200
}
201-
history.push(url);
201+
if (sandbox.isV2) {
202+
window.location.href = url;
203+
} else {
204+
history.push(url);
205+
}
202206
}
203207
};
204208

packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenus/BranchMenu.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@ import {
55
githubRepoUrl,
66
v2BranchUrl,
77
} from '@codesandbox/common/lib/utils/url-generator';
8-
import { useHistory } from 'react-router-dom';
98
import { Context, MenuItem } from '../ContextMenu';
109

1110
type BranchMenuProps = {
1211
branch: Branch;
1312
};
1413
export const BranchMenu: React.FC<BranchMenuProps> = ({ branch }) => {
1514
const { visible, setVisibility, position } = React.useContext(Context);
16-
const history = useHistory();
1715

1816
const { name, project, contribution } = branch;
1917
const branchUrl = v2BranchUrl({ name, project });
@@ -31,7 +29,13 @@ export const BranchMenu: React.FC<BranchMenuProps> = ({ branch }) => {
3129
position={position}
3230
style={{ width: 120 }}
3331
>
34-
<MenuItem onSelect={() => history.push(branchUrl)}>Open branch</MenuItem>
32+
<MenuItem
33+
onSelect={() => {
34+
window.location.href = branchUrl;
35+
}}
36+
>
37+
Open branch
38+
</MenuItem>
3539
<MenuItem onSelect={() => window.open(branchUrl, '_blank')}>
3640
Open branch in a new tab
3741
</MenuItem>

packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenus/SandboxMenu.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,17 @@ export const SandboxMenu: React.FC<SandboxMenuProps> = ({
127127
Fork Template
128128
</MenuItem>
129129
) : null}
130-
<MenuItem onSelect={() => history.push(url)}>Open {label}</MenuItem>
130+
<MenuItem
131+
onSelect={() => {
132+
if (sandbox.isV2) {
133+
window.location.href = url;
134+
} else {
135+
history.push(url);
136+
}
137+
}}
138+
>
139+
Open {label}
140+
</MenuItem>
131141
<MenuItem
132142
onSelect={() => {
133143
window.open(`https://codesandbox.io${url}`, '_blank');

0 commit comments

Comments
 (0)