Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when setting class of a <rect> inside <a> inside <svg> #14751

Closed
utkarshkukreti opened this issue Dec 18, 2024 · 1 comment · Fixed by #14756
Closed

Error when setting class of a <rect> inside <a> inside <svg> #14751

utkarshkukreti opened this issue Dec 18, 2024 · 1 comment · Fixed by #14756
Assignees

Comments

@utkarshkukreti
Copy link

utkarshkukreti commented Dec 18, 2024

Describe the bug

When setting a dynamic class on an SVG Element inside inside like this:

<script>
	let name = 'world';
</script>

<svg>
	<a href="/" aria-label="...">
		<rect class={name} />
	</a>
</svg>

I get this error on Chrome:

Cannot set property className of #<SVGElement> which has only a getter

Reproduction

https://svelte.dev/playground/hello-world?version=5.14.4#H4sIAAAAAAAAE22NQWrDMBBFrzL8TRJw7b0jG7rLHaIuFHmSGqaykSZuivHdixRCN90-3n9_RXBfjBYnFpnoe4oy0J6HUXk4oMJ1FE5ozyv0Z85eBqheq_d5rtPCopldXOL_uJ-CctCEFib5OM7a22BVWCnr1NGu_O6ONpjmzwgmLbeiGkefka-dRWNBLo7uTdyFpbOo69qiSFZNZK_kxaXUrTm9UfPcN64v7eXWo4LyQ9FqvPP2sf0CorvX0gIBAAA=

Logs

Cannot set property className of #<SVGElement> which has only a getter

System Info

Tested in the REPL with:

System:
  OS: macOS 15.0.1
Browsers:
  Brave Browser: 131.1.73.101
  Chrome: 131.0.6778.140
npmPackages:
  svelte: 5.14.4 => 5.14.4

Severity

blocking an upgrade

@utkarshkukreti
Copy link
Author

I found a workaround for now:

<svg>
  <svelte:element
    this={"a"}
    {...{ xmlns: 'http://www.w3.org/2000/svg' }}
    href="/"
    aria-label="...">
    <rect class={name} />
  </svelte:element>
</svg>

(xmlns is a spread to suppress TypeScript error)

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 a pull request may close this issue.

2 participants