From 1cb1a2fdae928f8bd48afe75c2cb8d046c769b60 Mon Sep 17 00:00:00 2001 From: Linh Vo Date: Tue, 2 Dec 2025 10:08:50 +0700 Subject: [PATCH] fix: prevent SVG clip path ID collisions in multiple QR code instances --- src/index.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 9a4bf5a..23d0c83 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -import React, { useMemo } from "react"; +import React, { useMemo, useId } from "react"; import Svg, { Defs, G, @@ -23,16 +23,19 @@ const renderLogo = ({ logoColor, logoMargin, logoBorderRadius, + clipPathId }) => { const logoPosition = (size - logoSize - logoMargin * 2) / 2; const logoBackgroundSize = logoSize + logoMargin * 2; const logoBackgroundBorderRadius = logoBorderRadius + (logoMargin / logoSize) * logoBorderRadius; - + const clipLogoBackgroundId = `clip-logo-background-${clipPathId}`; + const clipLogoId = `clip-logo-${clipPathId}`; + return ( - + - - + )} @@ -100,6 +103,8 @@ const QRCode = ({ onError, testID, }) => { + const clipPathId = useId(); + const result = useMemo(() => { try { return transformMatrixIntoPath(genMatrix(value, ecl), size); @@ -173,6 +178,7 @@ const QRCode = ({ logoColor, logoMargin, logoBorderRadius, + clipPathId, })} );