The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
code improvements
Pedro Ladeira6ff87238dbcd
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/installation-section.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/installation-section.tsxindex 953e4ddee2..1b378f9cfc 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/installation-section.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/installation-section.tsx@@ -18,7 +18,9 @@ export function InstallationSection() {loading: workspaceLoading,} = useWorkspace();const [savedStack, setSavedStack, { loading: stackLoading }] =- useWorkspaceStore<string[]>("analyticsSettingsSelectedStack");+ useWorkspaceStore<string[]>("analyticsSettingsSelectedStack", {+ mutateOnSet: true,+ });const [siteVisitEnabled] = useWorkspaceStore<boolean>("analyticsSettingsSiteVisitTrackingEnabled",);diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/publishable-key-field.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/publishable-key-field.tsxindex 0045ab17d6..04eaecbbe6 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/publishable-key-field.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/publishable-key-field.tsx@@ -69,7 +69,11 @@ export function PublishableKeyField({className="h-7 w-fit shrink-0 px-2.5"textWrapperClassName="overflow-visible"/>- <PublishableKeyMenu onRevoke={() => setShowRevokeModal(true)} />+ <PublishableKeyMenu+ onRevoke={() => setShowRevokeModal(true)}+ disabled={disabled}+ disabledTooltip={disabledTooltip}+ /></div></div>) : (diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/publishable-key-menu.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/publishable-key-menu.tsxindex 3a1e0ee049..961d45e838 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/publishable-key-menu.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/publishable-key-menu.tsx@@ -3,7 +3,15 @@ import { Button, Popover } from "@dub/ui";import { Delete } from "lucide-react";import { useState } from "react";-export function PublishableKeyMenu({ onRevoke }: { onRevoke: () => void }) {+export function PublishableKeyMenu({+ onRevoke,+ disabled,+ disabledTooltip,+}: {+ onRevoke: () => void;+ disabled?: boolean;+ disabledTooltip?: string;+}) {const [openPopover, setOpenPopover] = useState(false);return (@@ -20,6 +28,8 @@ export function PublishableKeyMenu({ onRevoke }: { onRevoke: () => void }) {}}icon={<Delete className="h-4 w-4" />}className="h-9 justify-start px-2 font-medium"+ disabled={disabled}+ disabledTooltip={disabledTooltip}/></div></div>@@ -32,6 +42,8 @@ export function PublishableKeyMenu({ onRevoke }: { onRevoke: () => void }) {variant="outline"className="size-7 shrink-0 border-transparent p-0 outline-none transition-all duration-200 data-[state=open]:border-neutral-500"icon={<ThreeDots className="size-4 shrink-0 rotate-90" />}+ disabled={disabled}+ disabledTooltip={disabledTooltip}onClick={() => {setOpenPopover(!openPopover);}}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/verify-install.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/verify-install.tsxindex 2b4e076890..702ce3aa49 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/verify-install.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/tracking/verify-install.tsx@@ -11,7 +11,7 @@ import { UserAvatar } from "@/ui/users/user-avatar";import { Button, Combobox, Globe } from "@dub/ui";import { cn, OG_AVATAR_URL, timeAgo } from "@dub/utils";import { useAction } from "next-safe-action/hooks";-import { type ReactNode, useMemo, useState } from "react";+import { type ReactNode, useMemo, useRef, useState } from "react";import { toast } from "sonner";const HOSTNAME_REQUIRED_MESSAGE =@@ -45,6 +45,9 @@ export function VerifyInstall({ hostnames }: { hostnames: string[] }) {const { id: workspaceId, role, store, mutate } = useWorkspace();const [selectedHostname, setSelectedHostname] = useState<string | null>(null);const [result, setResult] = useState<VerifyInstallationResult | null>(null);+ const selectedHostnameRef = useRef(selectedHostname);+ const pendingHostnameRef = useRef<string | null>(null);+ selectedHostnameRef.current = selectedHostname;const permissionsError = clientAccessCheck({action: "workspaces.write",@@ -80,9 +83,11 @@ export function VerifyInstall({ hostnames }: { hostnames: string[] }) {? lastVerified: null;- const showSuccess = result?.status === "success";- const showError = result?.status === "error";- const showLastVerified = !result && Boolean(persistedForHostname);+ const resultForSelection =+ result && result.hostname === selectedHostname ? result : null;+ const showSuccess = resultForSelection?.status === "success";+ const showError = resultForSelection?.status === "error";+ const showLastVerified = !resultForSelection && Boolean(persistedForHostname);const canReverify = showSuccess || showLastVerified;const helperTone: HelperTone | null = showSuccess@@ -99,16 +104,26 @@ export function VerifyInstall({ hostnames }: { hostnames: string[] }) {return;}- setResult(data);-if (data.status === "success") {void mutate();}++ if (data.hostname !== selectedHostnameRef.current) {+ return;+ }++ setResult(data);},onError({ error }) {+ const hostname = pendingHostnameRef.current;++ if (!hostname || hostname !== selectedHostnameRef.current) {+ return;+ }+setResult({status: "error",- hostname: selectedHostname ?? "",+ hostname,error: "unreachable",});toast.error(error.serverError || "Failed to verify installation.");@@ -138,9 +153,13 @@ export function VerifyInstall({ hostnames }: { hostnames: string[] }) {searchPlaceholder="Search hostnames..."buttonProps={{className: cn("h-10 w-full", helperTone && "bg-bg-default"),- disabled: hostnames.length === 0,+ disabled: hostnames.length === 0 || isPending,disabledTooltip:- hostnames.length === 0 ? HOSTNAME_REQUIRED_MESSAGE : undefined,+ hostnames.length === 0+ ? HOSTNAME_REQUIRED_MESSAGE+ : isPending+ ? "Verification in progress"+ : undefined,}}matchTriggerWidth/>@@ -151,10 +170,10 @@ export function VerifyInstall({ hostnames }: { hostnames: string[] }) {</HelperText>)}- {showError && result.status === "error" && (+ {showError && resultForSelection?.status === "error" && (<HelperText tone="error">- {ERROR_HEADLINE[result.error]} After correcting, try verifying again- and if the issue still persists, check out our{" "}+ {ERROR_HEADLINE[resultForSelection.error]} After correcting, try+ verifying again and if the issue still persists, check out our{" "}<ahref={VERIFY_DOCS_HREF}target="_blank"@@ -210,6 +229,7 @@ export function VerifyInstall({ hostnames }: { hostnames: string[] }) {return;}+ pendingHostnameRef.current = selectedHostname;void executeAsync({ workspaceId, hostname: selectedHostname });}}/>diff --git a/apps/web/lib/actions/verify-workspace-setup.ts b/apps/web/lib/actions/verify-workspace-setup.tsindex 5cc61ad5c6..f78780aa45 100644--- a/apps/web/lib/actions/verify-workspace-setup.ts+++ b/apps/web/lib/actions/verify-workspace-setup.ts@@ -89,7 +89,11 @@ export const verifyWorkspaceSetup = authActionClientimage: user.image ?? null,};- const store = (workspace.store as Record<string, unknown> | null) ?? {};+ const latest = await prisma.project.findUnique({+ where: { id: workspace.id },+ select: { store: true },+ });+ const store = (latest?.store as Record<string, unknown> | null) ?? {};await prisma.project.update({where: { id: workspace.id },diff --git a/apps/web/lib/analytics/verify-installation.ts b/apps/web/lib/analytics/verify-installation.tsindex b5fe3658e4..2805cc6248 100644--- a/apps/web/lib/analytics/verify-installation.ts+++ b/apps/web/lib/analytics/verify-installation.ts@@ -26,9 +26,10 @@ export type VerifyInstallationResult =const SCRIPT_TAG_RE = /<script\b[^>]*>/gi;const DUB_SCRIPT_RE =/dubcdn\.com\/analytics|data-sdkn=["']@dub\/analytics["']|@dub\/analytics/i;-const DUB_SRC_RE = /src=["'][^"']*dubcdn\.com\/analytics[^"']*["']/i;+const DUB_SRC_RE =+ /src\s*=\s*(?:["'][^"']*dubcdn\.com\/analytics[^"']*["']|[^\s>]*dubcdn\.com\/analytics[^\s>]*)/i;const CONVERSION_SRC_RE =- /src=["'][^"']*dubcdn\.com\/analytics[^"']*conversion-tracking[^"']*["']/i;+ /src\s*=\s*(?:["'][^"']*dubcdn\.com\/analytics[^"']*conversion-tracking[^"']*["']|[^\s>]*dubcdn\.com\/analytics[^\s>]*conversion-tracking[^\s>]*)/i;const SDK_NAME_RE = /data-sdkn=["']@dub\/analytics["']/i;const PUBLISHABLE_KEY_RE = /data-publishable-key=/i;