Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.3.2

### Patch Changes

- [`6c94dec`](https://github.com/bigcommerce/catalyst/commit/6c94dece0f72f2bc74ef67b456f2522475e2f129) Thanks [@chanceaclark](https://github.com/chanceaclark)! - Pulls in changes from the `@bigcommerce/catalyst-core@1.3.2` patch.

## 1.3.1

### Patch Changes
Expand Down
34 changes: 28 additions & 6 deletions core/data-transformers/scripts-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,30 @@ const BC_TO_C15T_CONSENT_CATEGORY_MAP = {
TARGETING: 'marketing',
} as const;

type ScriptInfo = { textContent: string } | { src: string } | null;

// C15T's ClientSideOptionsProvider creates the <script> element at runtime. BigCommerce's API
// returns inline scripts wrapped in <script> tags, which would result in nested <script> elements
// and cause errors.
function extractInlineScriptContent(scriptTag: string): string | undefined {
// and cause errors. This function extracts both inline content and src attributes to handle cases
// where InlineScript types may contain external script references.
function extractScriptInfo(scriptTag: string): ScriptInfo {
// Extract text content (for inline scripts)
const scriptMatch = /<script[^>]*>([\s\S]*?)<\/script>/i.exec(scriptTag);
const textContent = scriptMatch?.[1]?.trim();

if (textContent) {
return { textContent };
}

// Extract src attribute (for external scripts that may be misclassified as inline)
const srcMatch = /<script[^>]*\ssrc=["']([^"']+)["']/i.exec(scriptTag);
const src = srcMatch?.[1];

return scriptMatch?.[1];
if (src) {
return { src };
}

return null;
}

function isValidConsentCategory(key: string): key is keyof typeof BC_TO_C15T_CONSENT_CATEGORY_MAP {
Expand Down Expand Up @@ -57,10 +74,15 @@ export function scriptsTransformer(scripts: BigCommerceScripts): C15tScripts {
: undefined;

if (script.__typename === 'InlineScript' && script.scriptTag) {
const textContent = extractInlineScriptContent(script.scriptTag);
const scriptInfo = extractScriptInfo(script.scriptTag);

// Prefer textContent if available (true inline script)
if (scriptInfo !== null && 'textContent' in scriptInfo) {
return { ...baseConfig, textContent: scriptInfo.textContent, attributes };
}

if (textContent) {
return { ...baseConfig, textContent, attributes };
if (scriptInfo !== null && 'src' in scriptInfo) {
return { ...baseConfig, src: scriptInfo.src, attributes };
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@bigcommerce/catalyst-makeswift",
"description": "BigCommerce Catalyst is a Next.js starter kit for building headless BigCommerce storefronts.",
"version": "1.3.1",
"version": "1.3.2",
"private": true,
"scripts": {
"dev": "npm run generate && next dev",
Expand Down