svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Svelte 5 migration: statements should be reordered

Open Rich-Harris opened this issue 7 months ago • 0 comments

Describe the bug

in:

<script>
  $: mobile = width < 640;
  let width = 0;
</script>

<svelte:window bind:innerWidth={width} />

<p>{mobile ? 'mobile' : 'desktop'}</p>

out:

<script>
  let mobile = $derived(width < 640);
  let width = $state(0);
</script>

<svelte:window bind:innerWidth={width} />

<p>{mobile ? 'mobile' : 'desktop'}</p>

Note that width is referenced before its declaration. This is allowed in Svelte 4 but not in runes mode.

Reproduction

link

Logs

No response

System Info

next

Severity

annoyance

Rich-Harris avatar Jun 25 '24 16:06 Rich-Harris