Skip to content

feat: Add ability to comment out attributes#17188

Closed
Teiem wants to merge 3 commits intosveltejs:mainfrom
Teiem:attribute-comments
Closed

feat: Add ability to comment out attributes#17188
Teiem wants to merge 3 commits intosveltejs:mainfrom
Teiem:attribute-comments

Conversation

@Teiem
Copy link

@Teiem Teiem commented Nov 18, 2025

Relevant RFC, specifically this comment which has the most upvotes.

In short, this PR would allow comments in the form of {/* some comment*/} where an html attribute is expected, e.g.

<Tag {/* comment */}></Tag>

This would be useful to quickly comment out single attributes of an HTML element.
What does not work is using this to comment out the entire tag, for that we already have normal html comments (<!-- -->).

Implementation wise this is an empty attribute which will then be ignored by the parser.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2025

🦋 Changeset detected

Latest commit: 85242fc

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

This PR includes changesets to release 1 package
Name Type
svelte Minor

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

@svelte-docs-bot
Copy link

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@17188

@techniq
Copy link

techniq commented Nov 19, 2025

One workaround I use is to add an underscore (_) prefix to the prop/attribute

<Button _color="blue">

This works except for svelte-check getting cranky.

also if I'm trying a few options I will add additional underscores:

<Button _color="blue" __color="red" color="green">

Having a way to comment out attributes similar to React would be great though!

@Rich-Harris Rich-Harris mentioned this pull request Feb 10, 2026
6 tasks
@Rich-Harris
Copy link
Member

Thank you. I'm not personally sold on the syntax, it feels quite heavy to me, and it's something people have to learn. I'd rather be able to just use the same comments I already use in JS/TS. Opened #17671 as an alternative.

@Rich-Harris
Copy link
Member

Going to go ahead and close this in favour of #17671, since it now also works with print(...) and Prettier (and soon hopefully language-tools). Thanks for getting the ball rolling

Rich-Harris added a commit that referenced this pull request Feb 18, 2026
Alternative to #17188. I prefer this syntax, it's lighter and feels much
more natural to me. For me it's less about commenting things _out_ than
about just, well... commenting — I frequently want to do this sort of
thing:

```svelte
<button
  // when the user clicks the button, the thing should happen
  onclick={doTheThing}
>click me</button>
```

One difference between this and #17188 is that this doesn't add a node
to the AST, just like comments in CSS/JS. Haven't decided if that's
desirable or not. I think it's more correct (it's an AST, not a CST;
HTML comments are different insofar as they _can_ represent 'real'
nodes) but it might be less convenient when (for example)
pretty-printing.

### Before submitting the PR, please make sure you do the following

- [x] It's really useful if your PR references an issue where it is
discussed ahead of time. In many cases, features are absent for a
reason. For large changes, please create an RFC:
https://github.com/sveltejs/rfcs
- [x] Prefix your PR title with `feat:`, `fix:`, `chore:`, or `docs:`.
- [x] This message body should clearly illustrate what problems it
solves.
- [x] Ideally, include a test that fails without this PR but passes with
it.
- [x] If this PR changes code within `packages/svelte/src`, add a
changeset (`npx changeset`).

### Tests and linting

- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint`

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
@Teiem Teiem deleted the attribute-comments branch February 25, 2026 05:04
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