Skip to content

Conversation

@chanceaclark
Copy link
Contributor

What/Why?

This PR enhances the scripts-transformer.ts to properly handle HTML attributes from BigCommerce script tags beyond just src attributes.

What Changed

  • Added new extractAttributes() function that parses and extracts all HTML attributes from script tags (e.g., async, defer, data-*, crossorigin)
  • Modified extractScriptInfo() to preserve additional attributes when transforming scripts
  • Updated the transformer logic to merge extracted attributes with consent-based attributes

Why This Matters

Previously, the transformer only extracted src and inline content from BigCommerce script tags, losing important attributes like async, defer, or custom data attributes. This caused scripts to lose their intended loading behavior and metadata during transformation.

Technical Details:

  • The new extractAttributes() function uses regex to parse the opening <script> tag
  • Handles both boolean attributes (e.g., async, defer) and key-value attributes (e.g., data-category="analytics")
  • Boolean attributes are stored with empty string values per HTML spec
  • The src attribute is explicitly excluded since it's already handled separately
  • Extracted attributes are merged with consent manager attributes, with consent attributes taking precedence

Testing

Screenshot 2026-01-08 at 11 10 56 Screenshot 2026-01-08 at 11 11 07

Migration

Rebase the scripts-transformer.ts file.

@chanceaclark chanceaclark requested a review from a team as a code owner January 8, 2026 18:31
@changeset-bot
Copy link

changeset-bot bot commented Jan 8, 2026

🦋 Changeset detected

Latest commit: 030f2d3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bigcommerce/catalyst-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jan 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
catalyst Ready Ready Preview, Comment Jan 8, 2026 6:33pm

@chanceaclark chanceaclark added this pull request to the merge queue Jan 8, 2026
Merged via the queue into canary with commit b4b87a3 Jan 8, 2026
9 checks passed
@chanceaclark chanceaclark deleted the fix/scripts branch January 8, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants