Skip to content

Commit b8a5ba8

Browse files
authored
Make error handling more resilient & fix an issue with bad URLs being constructed (#20)
* Make error handling more resilient by using a button that can catch errors * Bump version * Fix bad URL being constructed
1 parent cd4df73 commit b8a5ba8

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "clone-with-devpod-extension",
33
"private": true,
4-
"version": "0.3.3",
4+
"version": "0.3.4",
55
"type": "module",
66
"license": "MIT",
77
"scripts": {

src/pages/content/CloneButton.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ButtonLink } from "@lib/components/Button";
1+
import { Button } from "@lib/components/Button";
22
import { useTooltip } from "@lib/hooks/useTooltip";
33
import { getSupportedIntegration } from "@lib/integrations";
44
import { EIntegrationParseError } from "@lib/integrations/error";
@@ -7,8 +7,9 @@ import { PortalProps } from "@lib/utils/dom/portal";
77
import { EError, ENoIntegrationError } from "@lib/utils/error";
88
import { ModalErrorBoundaryProvider } from "@lib/wrappers/ErrorBoundary";
99
import { DevPodLogo } from "@src/icons/devpod";
10-
import { StrictMode } from "react";
10+
import { StrictMode, useCallback } from "react";
1111
import { createPortal } from "react-dom";
12+
import { useErrorBoundary } from "react-error-boundary";
1213

1314
export function getDevPodUrl(url: string) {
1415
try {
@@ -32,7 +33,7 @@ export function getDevPodUrl(url: string) {
3233
const { hostname, protocol } = new URL(url);
3334

3435
const branchSuffix = branch ? `@${branch}` : "";
35-
return `https://devpod.sh/open#${protocol}://${hostname}/${repo}${branchSuffix}`;
36+
return `https://devpod.sh/open#${protocol}//${hostname}/${repo}${branchSuffix}`;
3637
} catch (error) {
3738
console.error(EError.serialize(error));
3839
throw error;
@@ -44,23 +45,29 @@ function CloneButtonInner({
4445
className,
4546
}: PortalProps & { className?: string }) {
4647
const { isHovering, bindTarget, bindTooltip } =
47-
useTooltip<HTMLAnchorElement>();
48+
useTooltip<HTMLButtonElement>();
49+
const { showBoundary: showError } = useErrorBoundary();
4850

49-
const link = getDevPodUrl(window.location.href);
51+
const clone = useCallback(() => {
52+
try {
53+
const link = getDevPodUrl(window.location.href);
54+
window.open(link, "_blank", "noreferrer");
55+
} catch (error) {
56+
showError(error);
57+
}
58+
}, [showError]);
5059

5160
return (
5261
<div className="flex justify-center items-center">
53-
<ButtonLink
54-
rel="noreferrer"
55-
target="_blank"
56-
href={link}
62+
<Button
63+
onClick={clone}
5764
color="primary"
5865
{...bindTarget}
5966
className={className}
6067
>
6168
<DevPodLogo aria-label="" className="w-6 h-6 text-primary-contrast" />{" "}
6269
DevPod
63-
</ButtonLink>
70+
</Button>
6471
{createPortal(
6572
<div
6673
className={clsx(

0 commit comments

Comments
 (0)