Skip to content

Conversation

@mkucmus
Copy link
Contributor

@mkucmus mkucmus commented Jan 5, 2026

Description

The btn class mapping fix affects CMS text elements like this API payload:

{
  "value": "<a target=\"_self\" href=\"https://frontends.shopware.com\" class=\"btn btn-primary\">documentation</a>"
}

or with btn-secondary.

Before fix: Rendered as plain with no styling (classes not transformed)

After fix: Rendered as with Tailwind classes:

<a href="..." class="rounded-md inline-block my-2 py-2 px-4 border border-transparent text-sm font-medium focus:outline-none disabled:opacity-75 bg-brand-primary text-brand-on-primary hover:bg-brand-primary-hover">
  documentation
</a>

Type of change

ToDo's

Screenshots (if applicable)

Additional context

@vercel
Copy link

vercel bot commented Jan 5, 2026

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

Project Deployment Review Updated (UTC)
frontends-starter-template-extended Ready Ready Preview, Comment Jan 9, 2026 8:49am
frontends-vue-starter-template Ready Ready Preview, Comment Jan 9, 2026 8:49am
old-frontends-demo Ready Ready Preview, Comment Jan 9, 2026 8:49am
shopware-frontends-docs Ready Ready Preview, Comment Jan 9, 2026 8:49am

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where CMS button links with Bootstrap-style classes (e.g., "btn btn-primary", "btn btn-secondary") from the API were not being properly transformed to Tailwind utility classes. The root cause was that the custom renderer was receiving a pre-transformed node instead of the original node, and the class matching logic had issues with the regex pattern.

Key changes:

  • Fixed the renderer to pass the original node to custom component renderers instead of the transformed node
  • Changed class matching from regex patterns to simpler .includes() checks for better reliability
  • Added explicit removal of "btn" class and trimming to ensure clean class transformation

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/cms-base-layer/app/helpers/html-to-vue/renderer.ts Fixed to pass original node instead of transformedNode to custom renderers, preserving original class attributes
packages/cms-base-layer/app/components/public/cms/element/CmsElementText.vue Updated button detection logic and class transformation to properly convert Bootstrap button classes to Tailwind classes
templates/vue-demo-store/uno.config.ts Added custom surface-surface-primary color override for the demo store theme
.changeset/dirty-hats-cry.md Added changeset documenting the button class transformation fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 77 to +87
_class = node.attrs.class
.replace(/\bbtn\s+/, "")
.replace(
"btn-secondary",
`${btnClass} bg-brand-secondary text-brand-on-secondary hover:bg-brand-secondary-hover`,
)
.replace(
"btn-primary",
`${btnClass} bg-brand-primary text-brand-on-primary hover:bg-brand-primary-hover`,
);
)
.trim();
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of replacements can lead to incomplete transformation. If the class attribute contains "btn" without a trailing space (e.g., "btn-primary btn" or just "btn"), the first replacement won't match, leaving "btn" in the final output. Consider replacing specific variants (btn-primary, btn-secondary) first, then removing any remaining "btn" word with a global word-boundary regex like /\bbtn\b/g to handle all cases regardless of position.

Copilot uses AI. Check for mistakes.
@patzick patzick merged commit c6b88b7 into main Jan 9, 2026
11 checks passed
@patzick patzick deleted the fix/cms-anchor-button branch January 9, 2026 09:33
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