The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Skip update if link is identical
Steven Teya9d22e5fd7ab
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.tsindex a73f548e05..fb6688ee17 100644--- a/apps/web/app/api/links/[linkId]/route.ts+++ b/apps/web/app/api/links/[linkId]/route.ts@@ -10,6 +10,7 @@ import { withWorkspace } from "@/lib/auth";import prisma from "@/lib/prisma";import { NewLinkProps } from "@/lib/types";import { updateLinkBodySchema } from "@/lib/zod/schemas";+import { deepEqual } from "@dub/utils";import { NextResponse } from "next/server";// GET /api/links/[linkId] – get a link@@ -70,11 +71,17 @@ export const PATCH = withWorkspace(...body,};+ // if link and updatedLink are identical, return the link+ if (deepEqual(link, updatedLink)) {+ console.log("Link is identical to updated link.");+ return NextResponse.json(link, { headers });+ }+if (updatedLink.projectId !== link?.projectId) {throw new DubApiError({code: "forbidden",message:- "Transferring links to another workspace is only allowed via the /links/[linkId]transfer endpoint.",+ "Transferring links to another workspace is only allowed via the /links/[linkId]/transfer endpoint.",});}