Skip to content

fix: setting class on SVG elements throws TypeError#3199

Merged
DylanPiercey merged 3 commits into
marko-js:mainfrom
vwong:fix/svg-classname-setter
May 21, 2026
Merged

fix: setting class on SVG elements throws TypeError#3199
DylanPiercey merged 3 commits into
marko-js:mainfrom
vwong:fix/svg-classname-setter

Conversation

@vwong
Copy link
Copy Markdown
Contributor

@vwong vwong commented May 21, 2026

SVG elements expose className as a getter-only SVGAnimatedString, so directly assigning element.className = value throws in strict mode. Revert to using setAttribute("class", ...) which works for both HTML and SVG elements.

Description

This PR fixes a regression in e6a46be whereby classNames to SVG cannot be set.

Checklist:

  • I have read the CONTRIBUTING document and have signed (or will sign) the CLA.
  • I have updated/added documentation affected by my changes.
  • I have added tests to cover my changes.

SVG elements expose `className` as a getter-only `SVGAnimatedString`,
so directly assigning `element.className = value` throws in strict mode.
Revert to using `setAttribute("class", ...)` which works for both HTML
and SVG elements.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 21, 2026

🦋 Changeset detected

Latest commit: dc9319a

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

This PR includes changesets to release 2 packages
Name Type
@marko/runtime-tags Patch
marko 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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fb11f268-d890-430f-8520-171e168ab420

📥 Commits

Reviewing files that changed from the base of the PR and between ff10f77 and dc9319a.

📒 Files selected for processing (1)
  • packages/runtime-tags/src/dom/dom.ts

Walkthrough

This PR fixes a TypeError that occurs when setting the class attribute on SVG elements, which have a getter-only className property. The fix replaces direct element.className assignment in the _attr_class function with a setAttribute call that handles string and object class values and removes the attribute on falsy values. The change includes a test fixture demonstrating SVG class binding, updated bundle artifacts reflecting the implementation, and a changeset documenting the patch release.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: resolving a TypeError when setting the class attribute on SVG elements.
Description check ✅ Passed The description is directly related to the changeset, explaining the regression, the root cause, and the solution with proper context and references.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DylanPiercey DylanPiercey merged commit d7e07f3 into marko-js:main May 21, 2026
2 of 5 checks passed
@vwong vwong deleted the fix/svg-classname-setter branch May 21, 2026 01:31
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.

2 participants