Skip to content

Svelte 5 migration: event modifier transformer doesn't respect indentation #12170

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

Closed
Rich-Harris opened this issue Jun 24, 2024 · 2 comments · Fixed by #12176
Closed

Svelte 5 migration: event modifier transformer doesn't respect indentation #12170

Rich-Harris opened this issue Jun 24, 2024 · 2 comments · Fixed by #12176
Labels
Milestone

Comments

@Rich-Harris
Copy link
Member

Rich-Harris commented Jun 24, 2024

Describe the bug

This...

<script>
  let count = 0;
</script>

<div>
  <div>
    <div>
      <div>
        <button on:click|preventDefault={() => count += 1}>
          clicks: {count}
        </button>
      </div>
    </div>
  </div>
</div>

...becomes this:

<script>
  let count = $state(0);
</script>

<div>
  <div>
    <div>
      <div>
        <button onclick={(event) => {
  event.preventDefault();
  count += 1
}}>
          clicks: {count}
        </button>
      </div>
    </div>
  </div>
</div>

Reproduction

demo

@Rich-Harris Rich-Harris modified the milestones: 6.0, 5.0 Jun 24, 2024
@Neptunium1129
Copy link

Off topic, how will this feature change?

on:click|self={test()}

@stalkerg
Copy link
Contributor

sorry for off topic too, but a new way to making events is ugly, old solutions with on:click|preventDefault much much better from readability and usability. Declarative way here is the best.
Just check how many boilerplate we will have:

<button on:click|preventDefault={() => count += 1}>

vs

<button onclick={(event) => { event.preventDefault(); count += 1; }}>

also in that case we have classic abstract leaking, if we will have function should they should worry about event's options and not about business logic. Yes we can do it in the arrow function in place and just call our function somewhere else but it extra boilerplate again.

Really, sorry, I started fighting after battle but it's looks really bad. :(

@dummdidumm dummdidumm mentioned this issue Jun 25, 2024
5 tasks
FoHoOV pushed a commit to FoHoOV/svelte that referenced this issue Jun 27, 2024
- add $state rune at correct location, fixes sveltejs#12171
- correctly indent event handlers, fixes sveltejs#12170
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants