Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix(qr-code): ensure compatibility with React components and OG context

Bharath Lakshman Kumar1b91086cd801
diff --git a/apps/web/app/api/qr/route.tsx b/apps/web/app/api/qr/route.tsx
index a4fc751b43..5202160ae8 100644
--- a/apps/web/app/api/qr/route.tsx
+++ b/apps/web/app/api/qr/route.tsx
@@ -33,6 +33,7 @@ export async function GET(req: NextRequest) {
width: size / 4,
excavate: true,
},
+ isOGContext: true,
}),
{
width: size,
diff --git a/apps/web/lib/qr/types.ts b/apps/web/lib/qr/types.ts
index 921e75d99e..cbac647afe 100644
--- a/apps/web/lib/qr/types.ts
+++ b/apps/web/lib/qr/types.ts
@@ -22,6 +22,7 @@ export type QRProps = {
style?: CSSProperties;
includeMargin?: boolean;
imageSettings?: ImageSettings;
+ isOGContext?: boolean;
};
export type QRPropsCanvas = QRProps &
React.CanvasHTMLAttributes<HTMLCanvasElement>;
diff --git a/apps/web/lib/qr/utils.tsx b/apps/web/lib/qr/utils.tsx
index 8ec8756393..a48e203efd 100644
--- a/apps/web/lib/qr/utils.tsx
+++ b/apps/web/lib/qr/utils.tsx
@@ -149,12 +149,13 @@ export function QRCodeSVG(props: QRPropsSVG) {
bgColor = DEFAULT_BGCOLOR,
fgColor = DEFAULT_FGCOLOR,
includeMargin = DEFAULT_INCLUDEMARGIN,
+ isOGContext = false,
imageSettings,
...otherProps
} = props;
const shouldUseHigherErrorLevel =
- imageSettings?.excavate && (level === "L" || level === "M");
+ isOGContext && imageSettings?.excavate && (level === "L" || level === "M");
// Use a higher error correction level 'Q' when excavation is enabled
// to ensure the QR code remains scannable despite the removed modules.
@@ -180,22 +181,35 @@ export function QRCodeSVG(props: QRPropsSVG) {
cells = excavateModules(cells, calculatedImageSettings.excavation);
}
- const { imgWidth, imgHeight, imgLeft, imgTop } =
- convertImageSettingsToPixels(calculatedImageSettings, size, numCells);
-
- image = (
- <img
- src={imageSettings.src}
- alt="Logo"
- style={{
- position: "absolute",
- left: `${imgLeft}px`,
- top: `${imgTop}px`,
- width: `${imgWidth}px`,
- height: `${imgHeight}px`,
- }}
- />
- );
+ if (isOGContext) {
+ const { imgWidth, imgHeight, imgLeft, imgTop } =
+ convertImageSettingsToPixels(calculatedImageSettings, size, numCells);
+
+ image = (
+ <img
+ src={imageSettings.src}
+ alt="Logo"
+ style={{
+ position: "absolute",
+ left: `${imgLeft}px`,
+ top: `${imgTop}px`,
+ width: `${imgWidth}px`,
+ height: `${imgHeight}px`,
+ }}
+ />
+ );
+ } else {
+ image = (
+ <image
+ href={imageSettings.src}
+ height={calculatedImageSettings.h}
+ width={calculatedImageSettings.w}
+ x={calculatedImageSettings.x + margin}
+ y={calculatedImageSettings.y + margin}
+ preserveAspectRatio="none"
+ />
+ );
+ }
}
// Drawing strategy: instead of a rect per module, we're going to create a