From b17f95f0b875f19758125264f89206cdfbbd24c8 Mon Sep 17 00:00:00 2001 From: Thomas Mair Date: Tue, 21 Oct 2025 08:37:25 +0200 Subject: [PATCH] fix: set `data-draft="true"` instead of `data-version="preview"` for CMPv3 compatibility The `data-version` attribute has been replaced with `data-draft` in CMPv3, but this was missing from the `@s-group/react-usercentrics@3.0.0` release. You will need to migrate your props after this update: ```diff --- +++ ``` --- README.md | 9 +++++---- src/components/UsercentricsScript.tsx | 11 ++++++----- tests/components/UsercentricsScript.test.tsx | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 59daf10..b8db61d 100644 --- a/README.md +++ b/README.md @@ -102,10 +102,11 @@ interface UsercentricsScriptProps settingsId: string /** - * Whether to run Usercentrics in "production" or "preview" mode - * @default "production" + * Whether to run Usercentrics in draft mode + * @default `false` + * @see https://usercentrics.com/docs/web/implementation/ui/optional-steps/#draft-script */ - version?: 'production' | 'preview' + draft?: boolean src?: never } @@ -114,7 +115,7 @@ interface UsercentricsScriptProps ;() => /** Preview mode for development */ -;() => +;() => /* Fixed language code */ ;() => diff --git a/src/components/UsercentricsScript.tsx b/src/components/UsercentricsScript.tsx index ab25757..6355684 100644 --- a/src/components/UsercentricsScript.tsx +++ b/src/components/UsercentricsScript.tsx @@ -16,10 +16,11 @@ interface UsercentricsScriptProps settingsId: string /** - * Whether to run Usercentrics in "production" or "preview" mode. - * @default "production" + * Whether to run Usercentrics in draft mode + * @default `false` + * @see https://usercentrics.com/docs/web/implementation/ui/optional-steps/#draft-script */ - version?: 'production' | 'preview' + draft?: boolean src?: never } @@ -41,7 +42,7 @@ export const UsercentricsScript: FC = ({ id = 'usercentrics-cmp', language, settingsId, - version, + draft = false, ...rest }) => { return ( @@ -50,7 +51,7 @@ export const UsercentricsScript: FC = ({ async={'async' in rest ? rest.async : true} data-language={language} data-settings-id={settingsId} - data-version={version} + data-draft={draft ? true : undefined} id={id} src={USERCENTRICS_WEB_CMP_LOADER_SCRIPT_URL} /> diff --git a/tests/components/UsercentricsScript.test.tsx b/tests/components/UsercentricsScript.test.tsx index 9fe2a53..140894e 100644 --- a/tests/components/UsercentricsScript.test.tsx +++ b/tests/components/UsercentricsScript.test.tsx @@ -17,9 +17,9 @@ describe('Usercentrics', () => { }) it('should render preview attribute', () => { - const result = renderToStaticMarkup() + const result = renderToStaticMarkup() - expect(result).toMatch('data-version="preview"') + expect(result).toMatch('data-draft="true"') }) it('should allow disabling default async prop', () => {